我在使用case语句时使用大于两个日期时间的问题。基本上我有一个名为" Status"其中包含" Open"," Hold","" Close"。我有另一栏作为到期时间和完成时间。
下面是我在SQL服务器中的查询。任何人都可以帮我找到"如果到期时间少于完成时间那么"逾期"否则"没有过期"其中的列状态名称为('打开','暂停')
SELECT CASE
WHEN SD.STATUSNAME IN ('Open','Onhold') AND wrd.DUEBYTIME < wrd.COMPLETEDTIME
THEN 'Over Due'
ELSE 'Not Over Due'
END AS 'OVER_DUE_STATUS'
,wrd.WORKORDERID AS REQUEST_ID
,AU.FIRST_NAME AS TECHNICIAN
,wrd.TITLE
,CAT.CATEGORYNAME
,dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (wrd.CREATEDTIME / 1000), '1970-01-01 00:00:00') "Created Time"
,dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (wrd.COMPLETEDTIME / 1000), '1970-01-01 00:00:00') "Completed Time"
,dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (WRDS.ASSIGNEDTIME / 1000), '1970-01-01 00:00:00') "Assigned Time"
,dateadd(s, datediff(s, GETUTCDATE(), getdate()) + (WRD.DUEBYTIME / 1000), '1970-01-01 00:00:00') "Due by"
,AUSR.FIRST_NAME AS Requester_name
,MD.MODENAME AS MODE_OF_REQUEST
,DPD.DEPTNAME
,SD.STATUSNAME
FROM WorkOrder WRD
LEFT JOIN AaaUser AUSR ON AUSR.USER_ID = WRD.REQUESTERID
LEFT JOIN ModeDefinition MD ON MD.MODEID = WRD.MODEID
LEFT JOIN DepartmentDefinition DPD ON DPD.DEPTID = WRD.DEPTID
LEFT JOIN WorkOrderStates WRDS ON WRDS.WORKORDERID = WRD.WORKORDERID
LEFT JOIN StatusDefinition SD ON SD.STATUSID = WRDS.STATUSID
LEFT JOIN CategoryDefinition CAT ON CAT.CATEGORYID = WRDS.CATEGORYID
LEFT JOIN AaaUser AU ON AU.USER_ID = WRDS.OWNERID