select isnull(你的字段,'x') from 表名提示如下:服务器: 消息 241,级别 16,状态 1,行 1
从字符串转换为 datetime 时发生语法错误。

解决方案 »

  1.   

    create table #t(date_ datetime)
    insert #t select '2006-04-20'
    union all select ''select * from #tdrop table #t/*
    date_                                                  
    ------------------------------------------------------ 
    2006-04-20 00:00:00.000
    1900-01-01 00:00:00.000
    */
    数据的类型需要控制,这样就可以
    create table #t(date_ varchar(10))
    insert #t select '2006-04-20'
    union all select nullselect isnull(date_,'x') [date_] from #t drop table #t
    /*
    date_      
    ---------- 
    2006-04-20
    x
    */
      

  2.   

    create table #t(date_ datetime)
    insert #t select '2006-04-20'
    union all select Null
    select isnull(convert(char(10),date_,120),'X') from #t