存储过程和动态SQL:
create procedure p_a (@a varchar)
as
declare @sql varchar(300)
set @sql = 'select a1,' +
           (case when a2 is null then '' else 'a2,' end) +
           (case when a3 is null then '' else 'a3,' end) +
           ......
           (case when a5 is null then '' else 'a5,' end) +
from table1 where a1 = @a
set @sql = left(@sql, len(@sql) - 1) + ' from table1 where a1 = "'+@a+'"'
exec (@sql)
go

解决方案 »

  1.   

    哦,如果是ACCESS数据库的话。就没有办法了吗?
      

  2.   

    如果字段不固定,是不是就没有其它方法了呢?(数据库为MS-SQL)
      

  3.   

    难一点,要从syscolumns表中取得表的所有字段,判断其值是否为NULL,再生成SQL语句
      

  4.   

    “稀疏数据表”不稀疏,一大堆的null就叫稀疏呀?create table 稀疏表不是表而是元素(行 varchar(10),列 varchar(10),值 varchar(30))