日期:2014-05-17 浏览次数:20470 次
DECLARE @a varchar(14) ='20120907112032' SELECT CONVERT(datetime,SUBSTRING(@a,1,4)+'-'+SUBSTRING(@a,5,2)+'-'+SUBSTRING(@a,7,2)+' '+SUBSTRING(@a,9,2)+':'+SUBSTRING(@a,11,2)+':'+SUBSTRING(@a,13,2))
------解决方案--------------------
declare @a char(14) declare @aa varchar(25) set @a='20120907112032' set @aa=left(@a,4)+'-'+right(left(@a,6),2)+'-'+right(left(@a,8),2)+' '+right(left(@a,10),2)+':'+right(left(@a,12),2)+':'+right(@a,2)+'.000' select cast(@aa as datetime) as '时间' /* -->测试结果 时间 --------------------------- 2012-09-07 11:20:32.000 */
------解决方案--------------------
DECLARE @a varchar(14) ='20120907112032' SELECT CONVERT(datetime,SUBSTRING(@a,1,4)+'-'+SUBSTRING(@a,5,2)+'-' +SUBSTRING(@a,7,2)+' '+SUBSTRING(@a,9,2)+':'+SUBSTRING(@a,11,2)+ ':'+SUBSTRING(@a,13,2)) ------------------------------ /* 无列名 2012-09-07 11:20:32.000 */
------解决方案--------------------
declare @a char(14) set @a='20120907112032' select convert(varchar(10),convert(datetime,left(@a,8)),120) +' '+SUBSTRING(@a,9,2)+':'+SUBSTRING(@a,11,2)+':'+SUBSTRING(@a,13,2) /* 2012-09-07 11:20:32 */
------解决方案--------------------