1
我想知道哪個用戶是晚上9點鐘的時鐘在晚上9點00分上午9點多宣佈爲晚,但我的結果顯示我超過了10點00分只是算晚了在SQL中轉換日期的時間
DECLARE @clockin as varchar
DECLARE @clockout as varchar
DECLARE @reportdate as datetime
--SET @clockin = CONVERT(108,'08:30')
SET @clockin = CONVERT(varchar(10),CAST('9:00' AS TIME),100)
SET @clockout = CONVERT(varchar(10),CAST('18:30' AS TIME),100)
SET @reportdate = month(GETDATE())
SELECT
u.showname AS showname,
l.USERID AS USERID,
u.BADGENUMBER AS BADGENUMBER,
l.CHECKTIME AS CHECKTIME,
CASE
WHEN DATEPART(HOUR, l.CHECKTIME) <= @clockin
THEN CONVERT(varchar(10), CAST(l.CHECKTIME AS TIME), 100)
ELSE 'late ' + CONVERT(varchar(100), CAST(l.CHECKTIME AS TIME), 100)
END AS Time
FROM
CHECKINOUT l
INNER JOIN
USERINFO u ON l.USERID = u.USERID
WHERE
u.showname IS NOT NULL
AND u.BADGENUMBER > 100
AND CHECKTIME >= '1 jan 2017'
AND CHECKTIME <= '31 jan 2017'
--GROUP BY l.USERID, u.showname, u.BADGENUMBER
ORDER BY
u.BADGENUMBER
結果
哪個RDBMS是爲了這個?請添加一個標籤來指定您是使用'mysql','postgresql','sql-server','oracle'還是'db2' - 或者其他的東西。 –