...表的某一列各自求和后,再四列相加等于另一表的某一列 存储过程...
发布网友
发布时间:2024-10-02 06:32
我来回答
共1个回答
热心网友
时间:2024-11-22 12:46
先定义四个变量来保存 你获取的四个求和结果
DECLARE @cgjhsl DECIMAL(10,2)
DECLARE @cgthsl DECIMAL(10,2)
DECLARE @xschsl DECIMAL(10,2)
DECLARE @xsthsl DECIMAL(10,2)
SELECT @cgjhsl=SUM( jhsl)
FROM [caigoujinhuo(采购进货)]
where [caigoujinhuo(采购进货)].spdm=@spdm1 and [caigoujinhuo(采购进货)] .spggdm =@spggdm1 and shanchu=0
Select @cgthsl=SUM (thsl)
from [caigoutuihuo(采购退货)]
where [caigoutuihuo(采购退货)].spdm=@spdm1 and [caigoutuihuo(采购退货)].spggdm=@spggdm1 and shanchufou=0
select @xschsl =SUM(chsl)
from [xiaoshouchuhuo(销售出货)]
where [xiaoshouchuhuo(销售出货)] .spdm=@spdm1 and [xiaoshouchuhuo(销售出货)].spggdm=@spggdm1 and shanchufou=0
select @xsthsl=SUM(xsthsl)
from [xiaoshoutuihuo(销售退货)]
where [xiaoshoutuihuo(销售退货)].spdm=@spdm1 and [xiaoshoutuihuo(销售退货)] .spggdm=@spggdm1 and shanchufou=0
insert into [kucun(库存表)] (spdm ,spggdm,kcsl) values (@spdm1,@spggdm1,(@cgjhsl+@cgthsl+@xschsl+@xsthsl))