sql中的isnull 可以来替换 null的字段为另外的值,但是这个isnull对''字符没用,对于''这种字符要替换的话,该咋弄呢?

解决方案 »

  1.   

    case when 字段='' then '值' end
      

  2.   

    select  case when colname='' then '你要显示的值' else colname end frin tablename
      

  3.   

    select  case when colname='' then '你要显示的值' else colname end from tablename
      

  4.   

    我需要在 select 中直接取得替换的结果,比如是null的 可以
    select isnull(a,b) 字段1 from 表
    但如果是 '' 空字符呢?
      

  5.   


    declare @table table (colname varchar(1))
    insert into @table
    select 'a' union all
    select 'b' union all
    select '' union all
    select 'd'select colname=case when colname='' then '你要显示的值' else colname 
    end
    from @table
    /*
    colname
    ------------
    a
    b
    你要显示的值
    d
    */