例如现查询出数据有10行,如果其中某一行的某一列值是null就过滤掉通常我们写法是select  a,b from tab where a is not null or b is not null 但是如果是很多个列这样写下去就很多哦,有没有更好的办法

解决方案 »

  1.   

    select * from tb where a+b+c+d is not null
      

  2.   

    这还麻烦?
    or好像不对,应该and
      

  3.   


    +
    利用null的计算逻辑可以处理。
      

  4.   

    --老实点,拼吧
    declare @sql varchar(max)
    declare @t nvarchar(255)set @t='表名'select @sql=ISNULL(@sql+'and ','')+name+' is not null ' from syscolumns where id=object_id(@t)
    exec('select * from '+@t+' where '+@sql)
      

  5.   

    如果N多个列都需要进行一次判断的话
    拼接判断要不写or或and要好些select * from tb where isnull(a,'') + isnull(b,'') + isnull(c,'') != ''