Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting a count result using case statement?

Status
Not open for further replies.

douggy

Technical User
Jan 18, 2001
78
GB
I am running a sql statement to count the number of each status. I have done an outer join as I need to see the status's that don't have any animals associated yet.

Where I have a count of 1 that is actually Zero. Can I do some kind of case statememt to convert the one's to zeros.

Many thanks
Mark

SQL
========================
SELECT TOP 100 PERCENT COUNT(dbo.TblArkStatus.Status) AS Expr1, dbo.TblArkStatus.Status
FROM dbo.TblArkStatus LEFT OUTER JOIN
dbo.TblArkAnimals ON dbo.TblArkStatus.StatusID = dbo.TblArkAnimals.CurrentStatus
GROUP BY dbo.TblArkStatus.Status
ORDER BY COUNT(dbo.TblArkStatus.Status)
===================================
Current query result;

1 EID X Check
1 Inform NSP/NSIP
1 Inform Owner
1 Nom SAMB Appd
1 Nom Soc Decline
1 P/W Recd Admin
1 P/W to Admin
1 Sent to Slgtr
1 Slgtr Pay Owner
1 Slgtr Pay Recd Ark
1 Retained Farm
2 BD IPX EDTA Comp
3 Nom Soc Appd
3 Return to Owner
4 Transport Out
 
Can you replace COUNT() with something like:

SUM (CASE WHEN dbo.TblArkAnimals.CurrentStatus IS NULL THEN 0 ELSE 1 END) as Expr1

?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top