dateadd seconds< dateadd天问题

时间:2018-06-14 09:26:42

标签: sql sql-server-2008-r2 dateadd

我遇到了一个问题,我试图在一天的特定时间段内显示升级问题。我希望根据升级的优先级查看今天的所有升级。

SELECT tas.TASK_ID as TICKET, 
tas.TASKNAME,
chg.ASLOGID as ASSIGNEE,
DATEADD(SECOND, logs.SUBMIT_DATE , '19700101') as SUBMIT_DATE,
tas.PRIORITY,
FROM dbo.TASK as tas,
dbo.CHANGE as chg,
dbo.WORKLOG as logs
WHERE chg.ASLOGID in ('Some Users')
and tas.TASKNAME like ('Escalation%')
and chg.CHANGE_ID = tas.TASK_ID
and logs.CHANGE_ID = chg.CHANGE_ID
and logs.SUBMIT_DATE = 
    (Select MAX(logs2.SUBMIT_DATE) from dbo.WORKLOG as 
    logs2 where logs2.CHANGE_ID = logs.CHANGE_ID)
    and DATEADD(SECOND, logs.SUBMIT_DATE , '19700101') < DATEADD(DD, CASE WHEN 
    tas.PRIORITY = 0 THEN -1
    WHEN tas.PRIORITY = 1 THEN -2
    WHEN tas.PRIORITY = 2 THEN -4
    ELSE -6 END, CURRENT_TIMESTAMP)
Order by SUBMIT_DATE

我的查询似乎在主要工作,但我不确定Second Max Select是否正常工作。会发生什么事情,我可以在一天开始时看到一些升级,但一旦他们在当天晚些时候被清除,另一个会在屏幕上弹出。昨天16点30分,屏幕上出现了下面的升级。据我所知,优先权没有变化。

+-----------------+-------------+----------+---------------------+----------+
|     TICKET      |  TASKNAME   | ASSIGNEE |     SUBMIT_DATE     | PRIORITY |
+-----------------+-------------+----------+---------------------+----------+
| INC000012345678 | Escalation  | User1    | 11/06/2018 09:41:51 |        1 |
+-----------------+-------------+----------+---------------------+----------+

正如我所说的那样,我尝试了当天可能会出现的所有问题,我很欣赏这个问题可能是在dateadd秒然后试图计算dateadd天数,但我本来期待的以上是09:41之后出现的?我对此比较陌生,所以我可能对它的工作方式有点天真。

欣赏正确的做法,并提前感谢。

1 个答案:

答案 0 :(得分:0)

解决方案:

and CAST(DATEADD(SECOND, logs.SUBMIT_DATE , '19700101') as DATE) < DATEADD(DD, CASE WHEN 
tas.PRIORITY = 0 THEN -1
WHEN tas.PRIORITY = 1 THEN -2
WHEN tas.PRIORITY = 2 THEN -4
ELSE -6 END, CURRENT_TIMESTAMP)