日期:2014-05-18 浏览次数:20512 次
select convert(char(10),cast(substring('2012030607:37:54',0,9)as DATEtime),120)+'-'+RIGHT('2012030607:37:54',8)
------解决方案--------------------
select convert(datetime,left('2012030607:37:54',8)+' '+right('2012030607:37:54', LEN('2012030607:37:54')-8),120) as [date] date 2012-03-06 07:37:54.000
------解决方案--------------------
习惯,在编码里面有些是以0开始的。
------解决方案--------------------
select substring(date,1,4)+'-'+substring(date,5,2)+'-'+substring(date,7,2)+' '+substring(date,9,8) as date from a 结果 date ---------------------- 2012-03-06 07:37:54 (1 行受影响)
------解决方案--------------------
create table tb(col varchar(16)) insert into tb values('2012030607:37:54') insert into tb values('2012030607:38:38') insert into tb values('2012030607:40:34') insert into tb values('2012030607:41:10') go select left(col,4) + '-' + substring(col,5,2) + '-' + substring(col , 7,2) + ' ' + right(col,8) from tb drop table tb /* ----------------------------------- 2012-03-06 07:37:54 2012-03-06 07:38:38 2012-03-06 07:40:34 2012-03-06 07:41:10 (所影响的行数为 4 行) */