请问:如何将特殊的日期型转换成满足要求的字符串?
测试数据:
日期型:
2004-1-14 00:00:00
2004-10-14 00:00:00
2004-3-1 00:00:00
2004-10-1 00:00:00
分别转换成字符串char(8)
20040114
20041014
20040301
20041001
我向right,left和subtring函数处理这些特殊的日期型数据,感觉太麻烦.
请问:有没有快捷的方式将这些日期型转换成为满足要求的字符串?

解决方案 »

  1.   

    declare @t datetime
    set @t='2004-1-14 00:00:00'
    select convert(varchar(8),@t,112)
      

  2.   

    请问,可否详细写一下?
    我的T-SQL知识比较弱
      

  3.   

    declare @t table([date] datetime)
    insert into @t select '2004-1-14 00:00:00'
    union all select '2004-10-14 00:00:00'
    union all select '2004-3-1 00:00:00'
    union all select '2004-10-1 00:00:00'select convert(varchar(8),[date],112) from @t