どの時計の時計が午前9時、午前9時より遅いのかを知りたいのですが、私の結果は10時より前に表示されます。日付時刻を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'のどれかを指定するタグを追加してください。 –