I have a table in SQL Server 2008 that looks kind of like this:
ID I1 I2 ... IN
-------------------------
1 2 3 ..... 2
2 0 0 ..... 0
3 2 1 ..... 5
Where IN is about 9 columns. What I need to do is count the number of rows, but skipping rows where the values of I1..IN are 0's. I'm new to SQL and I have basically something like this:
SELECT COUNT(ID) AS Expr1,
COUNT(I1) AS Expr2,
COUNT(I2) AS Expr3,
COUNT(IN) AS ExprN
FROM [mytable]
WHERE (Expr2 !=0)
AND (Expr3 != 0)
AND (ExprN != 0)
I imagine there is an easier and more efficient way of doing this? I need to ensure that all of the column entries are 0 (other than the ID). I would prefer not to rely on a single column being 0 or not to make the determination. I working with a database somebody already created and these 0's should have been NULLS.
Thanks!