MS SQL 2008 Count Non 0 rows

Hi,

I have a table with a int field.  Without using a sub query I'd like to count the number of rows based on a condition, i.e. count the number of rows where a column is not 0.  i.e.
SELECT *, (COUNT(* WHERE COL A IS NOT 0)) FROM tablename.
LVL 2
kintonAsked:
Who is Participating?
 
tim_csConnect With a Mentor Commented:
You coudl just do a SUM with a case statement.

SELECT SUM (WHEN COL <> 0 THEN 1 ELSE 0 END )
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
> Without using a sub query
you cannot do that at the same level as the query itself ...
0
 
kintonAuthor Commented:
Great, good answer!  Should have thought of that..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.