怎麼用T-SQL的IF語句判斷一個表中的某個字段是否為空呢???

解决方案 »

  1.   

    全为空?还是某行为空?
    if exists (select 1 from tb where col is not null)
    else
      

  2.   

    --全为空
    if exists (select 1 from tb where col is not null)
       print '不全为空'
    else
       print '全为空'--某行select id , case when col is null then '空' else '非空' end from tb
      

  3.   

    select 字段名 is null
    from 表名
      

  4.   

    select * from 表名 where isnull(字段名,'')='' 
      

  5.   

    写错了。
    if exists (select * from 表名 where 列名 is  null)
    print '存在列为空的'