detail_id(int) month1(int) mat (varchar(20)) qty(numeric(18,4))
84 1 Y005000033 6.0000
85 1 SF20512 .0000
86 1 P005000010 .0000
87 1 P012000035 22.5000
88 2 SF21936 22.5000
89 2 SF21936 2.0000
90 2 P001000016 23.5200
91 2 Y001000015 10.0800
當detail_id字段不重復,month1與mat這兩個字段重復時,將qty字段的數據相加
如上表變成如下的表,請問如何實現
detail_id(int) month1(int) mat (varchar(20)) qty(numeric(18,4))
84 1 Y005000033 6.0000
85 1 SF20512 .0000
86 1 P005000010 .0000
87 1 P012000035 22.5000
88 2 SF21936 24.5000
89 2 SF21936 24.5000
90 2 P001000016 23.5200
91 2 Y001000015 10.0800
我用如下函數實現時出qty為空的現象
CREATE function f_str1(@detail_id int,@mat varchar(20),@month1 int )
returns numeric(18,4)
as
begin
declare @qty numeric(18,4)
select @qty =@qty +qty from MC_Scheduler_In where detail_id<>@detail_id and mat=@mat and month1=@month1
return @qty
end
結果是這樣,請問是哪 兒出了問題,但是我在做字符相加時用相似的函數又沒有問題。
detail_id mat month1 qty
84 Y005000033 1 NULL
85 SF20512 1 NULL
86 P005000010 1 NULL
87 P012000035 1 NULL
88 SF21936 2 NULL
89 SF21936 2 NULL
90 P001000016 2 NULL
91 Y001000015 2 NULL