很有可能我的想法走错了路,而试图从中解脱出来让我走到了今天。在这里……寻求帮助。
我已经建立了一个很长的 Case When 语句,它告诉我交易的日期必须在什么时候完成,不包括周末,并将其命名为“所需的 SLA 日期”
我要做的是创建一个列,上面写着,是的,交易是在 SLA 日期或之前完成的。或否,它是在之后完成的。我的逻辑是使用下面的案例声明,在另一个案例声明中说当“eventCompleteDate”是>所需的SLA然后“是”否则“否”以MetSLA结束
CASE WHEN Doc IN ( 'POS', 'Card' )
THEN CAST(DATEADD(d, CASE DATEPART(dw, DateEntered)
WHEN 7 THEN 2
WHEN 1 THEN 1
ELSE 0
END, DateEntered) + ( DATEPART(dw,
DATEADD(d,
CASE DATEPART(dw,
DateEntered)
WHEN 7 THEN 2
WHEN 1 THEN 1
ELSE 0
END, DateEntered))
- 2 + 5 ) % 5
+ ( ( DATEPART(dw, DATEADD(d, CASE DATEPART(dw, DateEntered)
WHEN 7 THEN 2
WHEN 1 THEN 1
ELSE 0
END, DateEntered)) - 2 + 5 )
/ 5 ) * 7 - ( DATEPART(dw,
DATEADD(d,
CASE DATEPART(dw,
DateEntered)
WHEN 7 THEN 2
WHEN 1 THEN 1
ELSE 0
END, DateEntered)) - 2 ) AS DATE)
ELSE CAST(DATEADD(d, CASE DATEPART(dw, DateEntered)
WHEN 7 THEN 2
WHEN 1 THEN 1
ELSE 0
END, DateEntered) + ( DATEPART(dw,
DATEADD(d,
CASE DATEPART(dw,
DateEntered)
WHEN 7 THEN 2
WHEN 1 THEN 1
ELSE 0
END, DateEntered))
- 2 + 10 ) % 5
+ ( ( DATEPART(dw, DATEADD(d, CASE DATEPART(dw, DateEntered)
WHEN 7 THEN 2
WHEN 1 THEN 1
ELSE 0
END, DateEntered)) - 2 + 10 )
/ 5 ) * 7 - ( DATEPART(dw,
DATEADD(d,
CASE DATEPART(dw,
DateEntered)
WHEN 7 THEN 2
WHEN 1 THEN 1
ELSE 0
END, DateEntered)) - 2 ) AS DATE)
END AS 'Required SLA Date'