>I have a table with recordnumber, goodparts, badparts.
>
>I need to know how many records there are for each goodparts and badparts.
>
>Right now I run one query for each.
>
>Select Count(recordnumber) As r1 From myTable Where goodparts > 0
>Select Count(recordnumber) As r1 From myTable Where badparts > 0
>
>How can I combine these two querys together to try and save processing time.
>
>The SPT table I am accessing is db2.
select sum(case when GoodParts > 0 then 1 else 0 end) as GoodPartsCount,
sum(case when BadParts > 0 then 1 else 0 end) as BadPartsCount
from myTable
I wrote this statement for SQL Server, check the analogue in db2
If it's not broken, fix it until it is.
My Blog