我有一个“DaysUntilDue”列,说明何时需要完成文档。我需要使用“记录日”列根据“到期日”计算“到期日”,并排除周六和周日。
我所拥有的只是我知道我需要工作的列。我有来自排除 Sat 和 Sun 的 Case When 语句的代码,但不知道如何将其合并到我需要做的事情中。我有我需要的所有列,并且都以它们需要的方式链接。真的很挣扎如何发表声明说使用现有的“DaysUntilDue”从文档的“logTime”计算截止日期,但不包括周末
SELECT
CategoryName,
DocCategory,
DaysUntilDue,
TranNbr,
DueDate,
LogTime
FROM Queue INNER JOIN WQMTransactions ON Queue.TranNbr = WQMTransactions.TranNbr INNER JOIN
ServiceQ INNER JOIN CategoryList ON ServiceQn.TranID = CategoryList.TranID
INNER JOIN Category ON CategoryList.CategoryID = Category.CategoryID
ON Queue.CategoryID = Category.CategoryID AND Queue.TranID = ServiceQ.TranID
也许是因为睡眠不足,但从概念上讲,我无法确定该怎么做。
我假设我需要使用我为另一个 qry 做类似事情而构建的这个案例陈述。
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'