使用SQL Sever的2005減少時間問題?
從下面的查詢我得到的總的工作時間是指Outtime - 銀泰百貨,假設當我減去第二天時間是指顯示錯誤的時間
查詢
Select ID, Normal_Intime, Normal_Outtime, Date, Intime, outtime, CONVERT(char(8), CASE WHEN InTime < Outtime THEN CASE WHEN OutTime > Normal_Outtime THEN CAST(Normal_Outtime AS datetime) ELSE CAST(Outtime AS datetime) END - CASE WHEN InTime < Normal_Intime THEN CAST(Normal_Intime AS datetime) ELSE CAST(Intime AS datetime) END ELSE CASE WHEN InTime < Normal_Intime THEN CAST(Normal_Intime AS datetime) ELSE CAST(Intime AS datetime) END - CASE WHEN OutTime > Normal_Outtime THEN CAST(Normal_Outtime AS datetime) ELSE CAST(Outtime AS datetime) END END, 8) AS workedtime from table1
輸出
ID Normal_Intime, Normal_Outtime, Date Intime, Outtime, Worktime
01 10:00:00 19:00:00 01/09/2009 08:20:56 15:40:15 05:40:15
01 18:00:00 05:00:00 02/09/2009 15:00:59 08:20:16 13:00:00
第一個是正確的, 第二次工作時間應該給上午11點00分因爲銀泰時間18:00:00和外勤時間是05:00:00(次日上午05:00:00),現在工作時間爲18:00:00 - 05:00:00,因爲13:00:00 。它應該只給11:00:00
如何減去第二天的時間。
需要查詢幫助
仍然將日期存儲在varchar字段中? – MartW 2009-10-14 10:31:26