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.
| Author |
Topic |
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2004-04-09 : 05:00:59
|
Hello,SELECT COUNT(status) AS AFROM tblusersWHERE status = 3SELECT COUNt(status) AS BFROM tblusersWHERE status = 1How do I combine these two? So I have only one query?ResultA B2 1ThanxxNeutcomp  |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2004-04-09 : 05:34:10
|
| [code]SELECT COUNT(CASE WHEN status = 3 THEN 1 END) AS A , COUNT(CASE WHEN status = 1 THEN 1 END) AS B WHERE status IN (1, 3)[/code]Adding the WHERE doesn't change the result, but it may make the query faster by filtering the recordset before calculating the sums. |
 |
|
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2004-04-09 : 06:16:05
|
| thanxx,Final Query:SELECT COUNT(CASE WHEN status = 3 THEN 1 END) AS A ,COUNT(CASE WHEN status = 1 THEN 1 END) AS BFrom tblusersWHERE status IN(1, 3)You forgot the From line.CyaBjorn8-D |
 |
|
|
|
|
|