SQL update代码执行失败问题
现在要反写 表#tbl_QiTao 中的 供应字段,但是如果update 前不加if 判断的话,有写值没更新成功
加if 判断则update 成功。 代码如下:待高手解迷
---------更新供应字段
if @ItemSpe=9
begin
update A
set A.供应=isnull(A1.GYQty,0)
from #tbl_QiTao as A
left join (select Itemcode,whcode,buyer,ItemArri,sum(GYQty) as GYQty from #tbl_GY where ItemArri=9
group by Itemcode,whcode,buyer,ItemArri) as A1
on isnull(A.料号,0)=isnull(A1.Itemcode,0) and isnull(A.存储code,0)=isnull(A1.whcode,0)
and isnull(A.业务员code,0)=isnull(A1.buyer,0) and isnull(A.料品属性,0)=isnull(A1.ItemArri,0)
end
if @ItemSpe=10
begin
update A
set A.供应=isnull(A1.GYQty,0)
from #tbl_QiTao as A
left join (select Itemcode,whcode,buyer,ItemArri,sum(GYQty) as GYQty from #tbl_GY where ItemArri=10
group by Itemcode,whcode,buyer,ItemArri ) as A1
on isnull(A.料号,0)=isnull(A1.Itemcode,0) and isnull(A.存储code,0)=isnull(A1.whcode,0) and isnull(A.业务员code,0)=isnull(A1.buyer,0)
and isnull(A.料品属性,0)=isnull(A1.ItemArri,0)
end