我知道問題是什麼,但任何人都可以請建議如何解決此查詢。如何處理dateadd中的月份值
的問題是,當我在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
如果查詢在2013-04-29上執行,它應該是95840而不是98540。 – 2013-04-29 06:56:25