2014-02-25 56 views
-1

表列爲a (int), b (int), c (int)。而且我在這張桌子裏有太多的行。例如,我在該表中有10行。我想讓我的列數不爲空。在SQL Server 2008中獲取所有非空列數

在示例

enter image description here

所以我的結果將是6.所以,我怎麼能得到空列在T-SQL算什麼?

+2

請編輯問題以包含您想要的結果。 –

回答

-1
select count(a) from table1 
union all 
select count(b) from table1 
union all 
select count(c) from table1 

什麼?下面

0

查詢會給你算任何不爲空值:

SELECT COUNT(a)+COUNT(b)+COUNT(c) 
    FROM yourtable 
1

如果你想所有的值跨列數:

select count(a) + count(b) + count(c) as NonNullCount, 
     3*count(*) - (count(a) + count(b) + count(c)) as NullCount 
from table t; 

這應該給你的「6 「和」3「,你在問題中指定。

相關問題