我比较日期是否大于17:00:00然后如果>它应该返回其他早晨。比17:00:00我正在尝试CASE但是在>上给出错误<迹象,为什么?
ALTER PROCEDURE [dbo].[USP_Report_SelectComplaintsByShift]
@IsMorningEvening bit
AS
BEGIN
Begin Try
Select ComplaintID, ComplaintSubject, Complainants.ComplainantName as Complainant
CASE
Complaints.ClosingDateTime
When (Complaints.ClosingDateTime < '17:00:00') then 'Morning'
When (Complaints.ClosingDateTime > '17:00:00') then 'Evening'
End as ClosingShift
from Complaints Inner Join Complainants
ON Complaints.Complainant_ID = Complainants.ComplainantID
END
答案 0 :(得分:1)
只需使用hour
提取datepart()
:
Select ComplaintID, ComplaintSubject, Complainants.ComplainantName as Complainant
(case When (datepart(hour, Complaints.ClosingDateTime) < 17) then 'Morning'
else 'Evening'
End) as ClosingShift
from Complaints Inner Join
Complainants
on Complaints.Complainant_ID = Complainants.ComplainantID;