我有一个临时表,我试图将下面显示的日期转换为datetime。该列设置为varchar(50)。数据是从长度为50个字符的csv文件传输的。
[CODE]
SELECT [Date]
,Patient
,ISNULL(Doctor,-1) AS Doctor
,[Procedure]
,CAST(Charge AS decimal(8,2)) AS ChargeDecimal
FROM ##TempBellevueLoadCSV
--Result:
Date
00:00.0
15:00.0 --Shown below:
00:00.0
00:00.0
--Need Datetime format with today's date added like below:
Date
2017-03-08 15:00:00.000
SELECT
CAST('0000-00-00 '+ SUBSTRING(CAST(t.[Date] AS varchar(8)),1, 7)+'0.000'
AS varchar) AS [Date]
,Patient
,Doctor
,[Procedure]
,CAST(Charge AS decimal(8,2)) AS Charge
FROM ##TempBellevueLoadCSV as t
--This looks like it, but cannot cast into datetime.
--Could I do this??? Doesn't work.
CAST(GETDATE()+[Date]) AS datetime
- 更新:我需要将当前日期添加小时分钟秒作为数据的一部分。如何将今天的日期添加到我已经拥有的小时,分钟,秒中?
答案 0 :(得分:0)
SELECT CONVERT(DATETIME,[Date],103)[Date]
,Patient
,ISNULL(Doctor,-1) AS Doctor
,[Procedure]
,CAST(Charge AS decimal(8,2)) AS ChargeDecimal
FROM ##TempBellevueLoadCSV
答案 1 :(得分:0)