2014-02-25 55 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“,你在问题中指定。

相关问题