私は問題が何であるかを知っていますが、このクエリを解決する方法として誰でも提案できますか.
問題は、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