IF EXISTS (SELECT NAME FROM SYSOBJECTS WHERE NAME='PROC_销售发票与出库单匹配' AND TYPE='P')
DROP PROC PROC_销售发票与出库单匹配
GO
create PROC PROC_销售发票与出库单匹配
as
CREATE TABLE #AA
(
销售单号 INT,
发票金额 NUMERIC(18,6),
增值税额 NUMERIC(18,6))
INSERT INTO #AA (销售单号,发票金额,增值税额 )
SELECT 销售单号, SUM(发票金额),SUM(增值税额)
FROM 销售出库单明细表 GROUP BY 销售单号
declare PP3 SCROLL cursor for
select 销售单号,发票金额,增值税额 from #AA
SELECT *FROM #AA
open PP3
DECLARE @销售单号 INT, @发票金额 NUMERIC(18,6), @增值税额 NUMERIC(18,6)
fetch PP3 into @销售单号,@发票金额,@增值税额
while @@fetch_status=0
begin
update 销售发票 set 已分配发票金额=已分配发票金额+@发票金额,已分配增值税=已分配增值税+@增值税额 where 销售单号=@销售单号
fetch PP3 into @销售单号,@发票金额,@增值税额
end
close PP3
deallocate PP3
-- SELECT *FROM 销售发票
-- EXEC PROC_销售发票与出库单匹配