我想查询一个表中的一条数据是否含有 null字段,
 比如我一表中,有一条数据一共有6个列,我如何查询这6个列中为null的字段数的多少

解决方案 »

  1.   

    可以使用存储过程,利用IsNull函数进行判断,用foreach遍历所有的字段,在代码中使用DBNull判断
      

  2.   

    select 
    (case when col1 isnull then 1 else 0 end)+
    (case when col2 isnull then 1 else 0 end)+
    (case when col3 isnull then 1 else 0 end)+
    (case when col4 isnull then 1 else 0 end)+
    (case when col5 isnull then 1 else 0 end)+
    (case when col6 isnull then 1 else 0 end) as 空字段数
    from tabname
    where .....