2、查询后再赋值
if exists
(select client_Code,max(dealdate),Employee_Code1
from t_tend_info
where year(dealdate)=cast(@year as int)
and flag='T'
and Client_Code=@Client_Code
group by client_Code,Employee_Code1)
begin
select @Last_Come_Date=max(dealdate),@Last_Employee_Code=Employee_Code1
from t_tend_info
where year(dealdate)=cast(@year as int)
and flag='T'
and Client_Code=@Client_Code
group by client_Code,Employee_Code1
执行语句
end
if exists
(select client_Code,max(dealdate),Employee_Code1
from t_tend_info
where year(dealdate)=cast(@year as int)
and flag='T'
and Client_Code=@Client_Code
group by client_Code,Employee_Code1)
begin
select @Last_Come_Date=max(dealdate),@Last_Employee_Code=Employee_Code1
from t_tend_info
where year(dealdate)=cast(@year as int)
and flag='T'
and Client_Code=@Client_Code
group by client_Code,Employee_Code1
执行语句
end
然后对变量进行判断如是否为NUll以确定是否进行插入操作。