Create table test (Acode char(1), V1 int, V2 int, V3 int)
Insert into test values('A',3,4,6),('B',0,null,0),('C',2,3,3)
Select Acode,V1,V2,V3, Case When sum(d.val)<>0 Then sum(d.val) Else 1 End Target
from test
cross apply (values(v1),(v2),(v3)) d(val)
Group by Acode,V1,V2,V3
drop table test
No comments:
Post a Comment