我知道问题是什么,但任何人都可以建议如何解决此查询。
问题是当我在 dateadd 中计算几个月时,我得到的价值超过 98540 :(
declare @Basepool int =10000000
declare @transactioncount bigint =1
declare @Monthnum int=1
declare @ContractId int=1
select CASE @Basepool
WHEN 0 THEN 'N/A'
WHEN -1 THEN 'N/A'
ELSE CASE
WHEN SUM(SUM(@TransactionCount)) OVER (Partition by @ContractId) > @Basepool THEN 'IN-OVERAGE'
--WHEN SUM(SUM(B.TransactionCount)) OVER (Partition by @ContractId) + (SUM(SUM(B.TransactionCount)) OVER (Partition by @ContractId)/MonthNum) > U.BasePool THEN DATEADD(MM, 1, GETDATE())
ELSE CONVERT(VARCHAR(20),DATEADD(MM,CAST(ROUND((@Basepool - SUM(SUM(@TransactionCount)) OVER (Partition by @ContractId))
/(SUM(SUM(@TransactionCount)) OVER (Partition by @ContractId)/@Monthnum),0) as INT), GETDATE()),101)
--(basepool - sumcontract) / (sumcontract/monthNum ) is the expected months to reach overage
END
END AS ExpectedDate