用select name from syscolumns where id in(select id from sysobjects where name='test')取出列名的结果集,用游标遍历它,取len(name),输入为0的,懒得写了

解决方案 »

  1.   

    select 
         ID,
         case when col1 is null then 1 else 0 end +
         case when col2 is null then 1 else 0 end +
         ...
         case when coln is null then 1 else 0 end as 空列数
    from 
         tabname
      

  2.   

    LBYYBL(o_o), 你说的方法我用过了,记录多的话,执行都没反应了。有没有其他好方法啊?
      

  3.   

    同意 libin_ftsafe(子陌红尘) 的方法,用case when判断后相加即可select 
         ID,
         case when col1 is null then 1 else 0 end +
         case when col2 is null then 1 else 0 end +
         ...
         case when coln is null then 1 else 0 end as 空列数
    from 
         tabname
    where ID='id'  --只统计符合条件的纪录的null栏数
      

  4.   


    if object_id('tempdb..#aa')>0 drop table #aa
    select iid=identity(int,1,1),D.name into #aa from sysobjects M inner join syscolumns D on M.id=D.id where D.id=Object_id('Billhead')declare @sSQL varchar(8000)
    set @sSQL=''
    select @sSQl=@sSQL+'+case when '+name+' is null then 1 else 0 end' from #aaset @sSQL=stuff(@sSQl,1,1,',')exec('select sheetid'+@ssql+' from 表 where id=''id''')
      

  5.   

    今天又见识到了,不用程序直接sql文就可以的呀。
    sql浩如烟海!
    ^_^
      

  6.   

    if exists(select * from sysobjects where name='t1') drop table t1
    create table t1 (id int,pid int,value varchar(50),value1 varchar(50))
    insert t1 (id,value)
    values(1,'A')select * from t1select case when id is null then 1 else 0 end+
    case when pid is null then 1 else 0 end +
    case when value is null then 1 else 0 end +
    case when value1 is null then 1 else 0 end as 空列数
    from t1 where id=1
    *********************************************************(所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)