开发者

SQL Stored Procedure - Count Specific Not Null Columns in a Row

I have a table with multiple columns and rows - from which I need to select th开发者_JAVA技巧e 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


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 = ?


select count(*) from table where data != null and structure !=null and loadid = a number
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜