Wednesday, August 20, 2008

Query for Goodness

Here is a query for work. Needed to know that state of the system, so I returned it's goodnesss. Good example of useing a case statement in sql



select case
when good = 3 and bad = 0 and ugly = 0 then 'good'
when bad = 1 then 'bad'
when ugly > 0 then 'ugly'
end as 'Goodness'
from
(select count(*) as good from dbUpdateVersion where dbversion in (399,401,402) ) tbl1,
(select count(*) as bad from dbUpdateVersion where dbVersion = 400 ) tbl2,
(select count(*) as ugly from dbUpdateVersion where dbversion > 402 ) tbl3

No comments: