字段sj为datetime类型
现在要显示成:如果sj字段的值为Null,则显示"未接收",否则显示sj的值
case sj is null or sj='' when true then '未接收' when false then cast(sj as varchar(20)) end
这样为什么不对呢?

解决方案 »

  1.   

    case sj is null or sj='' when '未接收' then cast(sj as varchar(20)) end
      

  2.   

    case when sj is null or sj='' then '未接收' 
         else cast(sj as varchar(20)) end
      

  3.   

    case when sj is null or sj='' then '未接收' else cast(sj as varchar(20)) end
      

  4.   

    select case when isnull(sj,'')='' then '未接收' ELSE CONVERT(VARCHAR(20),SJ,120) END FROM TB
      

  5.   

    case isnull(cast(sj as varchar),'')='' when '未接收' then cast(sj as varchar(20)) end
      

  6.   


    declare @tb table(sj datetime)insert @tb select null union all select getdate()select case when sj is null  then '未接收' else convert(varchar(19),sj,120) end 状态  from @tb既然SJ是为DATETIME类型就不需要or SJ=''
      

  7.   

    select case when isnull(sj,'')='' then '未接收' ELSE CONVERT(VARCHAR(20),SJ,120) END FROM TABLE
      

  8.   

    case when sj is null then '未接收' else cast(sj as varchar(20)) end