select (case(列1 is null)then 0 else 1 end + case(列2 is null)then 0 else 1 end +...... ) 数据个数 from 表

解决方案 »

  1.   

    select case when 列1 is null then 0 else 1 end+case when 列2 is null then 0 else 1 end+...... as 非空数据个数 from 表
      

  2.   

    系统存储过程sp_help 中可以读取该表一共有几个字段,我都没写过这样的语句,学习ing~
    呵呵,:)
      

  3.   

    首先,建立存储过程:
    CREATE   procedure GetField @tablename char(30), @alias varchar(10) = ''
    as
    declare @list varchar(500), @list1 varchar(500)         -- 长度不够时用list1
    select @list = ''
    select @list1=''
    declare @id int
    declare @fieldname varchar(30)
    select @id = id from sysobjects where name = @tablename
    declare mycur cursor for select name from syscolumns where id = @id
    open mycur
    fetch next from mycur into @fieldname
    WHILE (@@FETCH_STATUS = 0 )
    BEGIN
    if @alias <> ''
    begin
    select @fieldname = @alias + '.' + @fieldname
    end
    if (len(@list1)>0) or (len(@list)+len(@fieldname)>252)
    begin
    select @list1 = @list1 + @fieldname
    select @list1 = @list1 + ','
    end
    else
    begin
    select @list = @list + @fieldname
    select @list = @list + ','
    end
    fetch next from mycur into @fieldname
    END
    close mycur
    deallocate mycur
    if len(@list1)>0 
    select @list1 = substring(@list1, 1, len(@list1)-1)
    else
    select @list = substring(@list, 1, len(@list)-1)
    select @list, @list1
    如何就可以用存储过程来调用字段了——
    语法:
    getfield yourtablename