-1

我在使用案例条款时遇到了一些麻烦。问题出在以 DueBeyond 结尾的最后一部分,我需要这个来返回我们系统中明天之后到期的任何订单,如从今天起 2 天。抱歉太明显了。

SUM(CASE WHEN CURRENT_TIMESTAMP > oi.RequiredByDate THEN 1 ELSE 0 END) as PastDue
,SUM(CASE WHEN DATEADD(dd, DATEDIFF(dd, 0, oi.RequiredByDate), 0) = dateadd(day,     datediff(day, '19000101',CURRENT_TIMESTAMP),'19000102') then 1 ELSE 0 END) as DueTomorrow
,SUM(CASE WHEN dbo.TruncateDate(CURRENT_TIMESTAMP) = dbo.TruncateDate(oi.RequiredByDate) THEN 1 Else 0 END) as DueToday
,SUM(CASE WHEN DateDiff(day, getdate(), RequiredByDate) BETWEEN 2 and 7 AND DateName(weekday, RequiredByDate) = 'Monday' Then 1 ELSE 0 END) as DueMonday
,SUM(CASE WHEN dbo.TruncateDate(CURRENT_TIMESTAMP) <= dbo.TruncateDate(oi.RequiredByDate) THEN 1 ELSE 0 END) as DueBeyond
4

1 回答 1

0

如果您在当前日期上加上两天,然后查看该日期是否仍小于或等于您要求的日期,则它必须不早于未来两天。

,SUM(CASE WHEN DATEADD(DAY, 2,dbo.TruncateDate(CURRENT_TIMESTAMP)) <= 
     dbo.TruncateDate(oi.RequiredByDate) THEN 1 ELSE 0 END) as DueBeyond 
于 2012-04-18T23:45:26.490 回答