views:

31

answers:

2

Hey hey!

I have a table with multiple columns and rows - from which I need to select the count of two specific columns which are not null.

In other words:

LoadID,StudyID,Data,Structure,Status,Progress,Error,FileType

Select the count of not null data and structure where LoadID= a number

I know I could do nested IFs, but I wonder if there isn't a shorter, neater way to do this?

Regards, Byron Cobb

A: 
select count(*) from table where data != null and structure !=null and loadid = a number
NimChimpsky
I need to select the number of columns not null in the row, not the number of rows.
Byron Cobb
not sure I understand entirely, do you want a count for each row or a total count of all null values; but cte's (common table expression) may be useful.
NimChimpsky
I'll try explain best I can : Select 1 row - select data, if it's null count+=1, select structure, if it's null count+=1. I need to do something like that in sql server 2008 stored procedure.
Byron Cobb
+1  A: 
select case when Data is null then 1 else 0 end + 
case when Structure is null then 1 else 0 end as null_columns_amount 
from YourTable 
where LoadID = ?
Tommi
Perfect, Thanks!
Byron Cobb