日期:2014-05-18 浏览次数:20687 次
declare @a varchar(14) declare @c varchar(6) declare @b datetime set @a ='20111101000000' set @c = substring(@a,1,8) print @c set @b = convert(datetime,@c,120) print @b
declare @a varchar(14) declare @c varchar(8) --楼主注意这里,截取的是8位,但定义了6位。 declare @b datetime set @a ='20111101000000' set @c = substring(@a,1,8) print @c set @b = convert(datetime,@c,112) print @b
------解决方案--------------------
declare @a varchar(14) declare @c varchar(8) declare @b datetime set @a ='20111101000000' set @c = substring(@a,1,8) print @c set @b = convert(VARCHAR(10),@c,120) print CONVERT(VARCHAR(10),@b,120)
------解决方案--------------------
declare @a varchar(14) declare @c varchar(6) declare @b datetime set @a ='20111101000000' print CONVERT(VARCHAR(23),CONVERT(DATETIME,LEFT(@a,8)),121)
------解决方案--------------------
declare @a varchar(14) set @a ='20111101000000' print CONVERT(VARCHAR(23),CONVERT(DATETIME,LEFT(@a,8)),121)