22,210
社区成员
发帖
与我相关
我的任务
分享
if(@Type='I01' or @Type='I02' or @Type='I03')
begin
declare UpdateSumCursor cursor
for select ProductCode,PlanCount,WareHouseCode
,StoreCellICode from WH_OutBillDetail where OutBillCode=@WorkCode
open UpdateSumCursor
declare @Pcode varchar(50), @Plan int, @WHCode varchar(50) , @Scode varchar(50)
fetch next from UpdateSumCursor into @Pcode,@Plan,@WHCode,@Scode
while @@fetch_status=0
begin
select @RealQty=RealQty from WH_StockTotalQty where WareHouseCode=@WHCode and ProductCode=@Pcode
set @NewRealQty=@RealQty-@Plan
update WH_StockTotalQty set RealQty=@NewRealQty where WareHouseCode=@WHCode and ProductCode=@Pcode
fetch next from UpdateSumCursor into @Pcode,@Plan,@WHCode,@Scode
end
close UpdateSumCursor
deallocate UpdateSumCursor
end
select @ProductCode=ProductCode,@PlanCount=PlanCount,@WareHouseCode=WareHouseCode
,@StoreCellICode=StoreCellICode
from WH_OutBillDetail where OutBillCode=@WorkCode---删掉
select @RealQty=RealQty from WH_StockTotalQty where WareHouseCode=@WareHouseCode and ProductCode=@ProductCode
set @NewRealQty=@RealQty-@PlanCount 放到下面循环里
把你声明的那些列都赋值给变量不就行了。然后循环查询更新。if(@Type='I01' or @Type='I02' or @Type='I03')
begin
UPDATE b
SET RealQty=b.RealQty-a.PlanCount
FROM (SELECT ProductCode,WareHouseCode,SUM(PlanCount) AS PlanCount FROM WH_OutBillDetail WHERE OutBillCode=@WorkCode GROUP BY ProductCode,WareHouseCode) AS a
INNER JOIN WH_StockTotalQty AS b ON b.ProductCode=a.ProductCode AND b.WareHouseCode=a.WareHouseCode
END