shpresa
asked on
Sum Case in MS SQl
Ho can I make a sum case statement work
SUM(
(case
when a.var1 = 9 then 0 else a.var1 +
when a.var2 = 9 then 0 else a.var2 )
) as sumbeg,
SUM(
(case
when a.var1 = 9 then 0 else a.var1 +
when a.var2 = 9 then 0 else a.var2 )
) as sumbeg,
ASKER
I have a big query in a store procedur. So I am taking only the part that I need to change.
This is how it was originally,
Select A, B, C, D,
SUM((ISNULL(s.var1,0)) + (ISNULL(s.var2,0)) as sumbeg,
SUM((ISNULL(a.var1,0)) + (ISNULL(a.var2,0)) as summid,
All I need to do is to exclude the value s.var1 = 9 and make it 0 the same for var2
This is how it was originally,
Select A, B, C, D,
SUM((ISNULL(s.var1,0)) + (ISNULL(s.var2,0)) as sumbeg,
SUM((ISNULL(a.var1,0)) + (ISNULL(a.var2,0)) as summid,
All I need to do is to exclude the value s.var1 = 9 and make it 0 the same for var2
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks a lot. U are awesome
anyway test that, if it didn't 'work fr, please attache an example..
Open in new window