使用SQL Server 2000:將字符串轉換成datetime問題
SELECT PERSONID,
CARDEVENTDATE,
INTIME,
CASE
WHEN OUTTIME = INTIME THEN
'No PunchOut'
ELSE
OUTTIME
END AS OUTTIME,
CONVERT(char(8), CASE
WHEN DateAdd(Day, - DateDiff(Day, 0, OutTime), OutTime) > '18:00:00' THEN
Cast('18:00:00' AS datetime)
ELSE
DateAdd(Day, - DateDiff(Day, 0, OutTime), OutTime)
END - CASE
WHEN DateAdd(Day, - DateDiff(Day, 0, InTime), InTime) < '09:00:00' THEN
Cast('09:00:00' AS datetime)
ELSE
DateAdd(Day, - DateDiff(Day, 0, InTime), InTime)
END, 8) AS WorkTime
FROM (SELECT T_PERSON.PERSONID,
T_CARDEVENT.CARDEVENTDATE,
MIN(T_CARDEVENT.CARDEVENTTIME) AS INTIME,
MAX(T_CARDEVENT.CARDEVENTTIME) AS OUTTIME
FROM T_PERSON
INNER JOIN T_CARDEVENT ON T_PERSON.PERSONID = T_CARDEVENT.PERSONID
GROUP BY T_PERSON.PERSONID, T_CARDEVENT.CARDEVENTDATE) DERIVEDTBL
T_cardevent.cardeventtime列數據類型是VARCHAR。
在表Cardeventtime值是080002,091235 ....等等...,
當我執行上述查詢它示出了用於將表達式轉換爲數據類型日期時間算術快遞溢出錯誤。
@marc_s。但日期也顯示爲01/01/1900 08:00:02。我只需要時間 – Gopal 2009-09-27 15:11:50
然後使用轉換(DATETIME,,101)。關於轉換查看更多信息:http://msdn.microsoft.com/en-us/library/ms174420.aspx –
tster
2009-09-27 15:34:09
@Gopal:在SQL Server 2000中,你只有DATETIME其中包含日期和時間。只有SQL Server 2008有一個特定的TIME數據類型,只有TIME。 – 2009-09-27 17:13:13