非空字段数

select   count(*)   '总字段数',
   ISNULL(ISNULL(sum(case   when   
   isnullable=0   then   1  end),null),null) as '非空字段数'  
  from   syscolumns   where   id=object_id( 'EmpInfo')
--空字段总数
SELECT 
(
 (SELECT COUNT(*) FROM syscolumns WHERE id=object_id('表名'))-
 (SELECT sum(CASE WHEN isnullable=0 then 1 end) FROM syscolumns 
 WHERE id=object_id('EmpInfo'))
)as '空字段总数'
posted @ 2018-01-27 09:43  _NickWang  阅读(380)  评论(0编辑  收藏  举报