Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Case statement

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-11-04 : 11:08:34
How do I add a case statement to this query that if any of the fields are 0 then put a 0 in it's place?


Select

Case

pend400

when pend400=0 then '0'

else 0 end pend400


reg,regionacronym, totpenfodds, ABS(PendinFO) as Pendinfo, pendndds, pendfo300, penddds300,pend250, pend300, pend351, pend400

From

(Select Sort, area, Reg, regionacronym,

SUM(Totpenfodds) AS Totpenfodds,

sum(pendndds) as Pendndds,

(sum (Pendndds - Totpenfodds )) as PendinFO,


SUM(Pendfo300) AS Pendfo300,

SUM(Penddds300) AS Penddds300,

SUM(Pend250) AS Pend250,

SUM(Pend300) AS Pend300,

SUM(Pend351) AS Pend351,

SUM(pend400) AS pend400

from test

WHERE reg= 'c'
group by sort, area, Reg, regionacronym

)a

order by sort





JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-11-04 : 11:13:51
never mind I figured it out

Select
Case
when pend400 = '0' then '0'
else pend400
end,
Go to Top of Page
   

- Advertisement -