当前位置: 代码迷 >> Sql Server >> 日期类型转换有关问题
  详细解决方案

日期类型转换有关问题

热度:67   发布时间:2016-04-27 17:44:13.0
日期类型转换问题急
要求日期是2007.01.03的格式,但是数据出现  
2007.1.3  
2007.01.3  
2007.1.03等不规范数据
使用convert(char(10),日期,102)转换不了   请问如何处理

------解决方案--------------------
declare @t table(a varchar(20))
insert into @t
select '2007.1.3 '
union all select '2007.01.3 '
union all select '2007.1.03 '

select convert(char(10),cast(a as datetime),102) as a from @t
/*
a
----------
2007.01.03
2007.01.03
2007.01.03

(所影响的行数为 3 行)
*/
  相关解决方案