正如许多评论所说,以这种方式存储日期是一个坏主意。不过,这是将数值转换为 1 的DATETIME
一种方法:
DECLARE @Date NUMERIC(17,9)
SET @Date = 20130623.143448060
SELECT DATEADD(HOUR,-4,CONVERT(DATETIME,LEFT(YourDate,8)+' '+
SUBSTRING(YourDate,10,2)+':'+
SUBSTRING(YourDate,12,2)+':'+
SUBSTRING(YourDate,14,2)+'.'+
SUBSTRING(YourDate,15,3))) YourDate
FROM ( SELECT CONVERT(VARCHAR(18),@Date) YourDate) A
结果:
╔═════════════════════════╗
║ YourDate ║
╠═════════════════════════╣
║ 2013-06-23 10:34:48.807 ║
╚═════════════════════════╝
从这里,您可以随意格式化该日期。
更新
如果您需要在Date
列上使用此转换,则只需使用:
SELECT ItemId,
DATEADD(HOUR,-4,CONVERT(DATETIME,LEFT([Date],8)+' '+
SUBSTRING([Date],10,2)+':'+
SUBSTRING([Date],12,2)+':'+
SUBSTRING([Date],14,2)+'.'+
SUBSTRING([Date],15,3))) [Date],
[Object],
SourceSite,
DestSite
FROM ( SELECT ItemId,
CONVERT(VARCHAR(18),[Date]) [Date],
[Object],
SourceSite,
DestSite,
UserCode
FROM JnlMediumMove) A
WHERE UserCode = 'Automation'
AND LEFT([Date],8)=CONVERT(VARCHAR(8),GETDATE()-1,112)
ORDER BY [Date] DESC;