日期:2014-05-18 浏览次数:20586 次
SELECT REPLACE(REPLACE(REPLACE(REPLACE(convert(varchar(50),GETDATE(),121),'-',''),':',''),' ',''),'.','')
------解决方案--------------------
字符串转化到时间格式,先创建个函数,然后调用函数就行了
CREATE FUNCTION ChangeStrToDate(@Str VARCHAR(100)) RETURNS VARCHAR(100) AS BEGIN DECLARE @Date VARCHAR(10) DECLARE @Time VARCHAR(100) DECLARE @Month VARCHAR(10) DECLARE @Min VARCHAR(10) SET @Date = LEFT(@Str,8) SET @Time = RIGHT(@Str,9) SET @Month = SUBSTRING(@Date,5,2) SET @Date = STUFF(@Date,5,2,'-' + @Month + '-') SET @Min = SUBSTRING(@Time,3,2) SET @Time = STUFF(STUFF(@Time,3,2,':' + @Min + ':'),9,0,'.') RETURN @Date + ' ' + @Time END GO SELECT DBO.ChangeStrToDate('20120418045858977')