检查SQL中的两个值之间是否有时间

时间:2016-11-17 20:09:55

标签: sql-server-2008

我想在SQL中获得类似下面的内容

if (current time in between 5AM to 3PM )
then print "firsshift"
else (current time in between 5AM to 3PM)
then print "second shift"

1 个答案:

答案 0 :(得分:2)

DECLARE @CurrentTime AS TIME

SET @CurrentTime = GETDATE()

SELECT @CurrentTime AS CurrentTime,
CASE 
    WHEN @CurrentTime BETWEEN '5:00:00' AND '15:00:00' THEN
        'First Shift'
    ELSE
        'Second Shift'
END AS WhichShift