1

收到此错误:

向“日期时间”列添加值导致溢出。

CASE U.BasePool 
            WHEN 0 THEN 'N/A'
            WHEN -1 THEN 'N/A'
            ELSE CASE 
                    WHEN SUM(SUM(B.TransactionCount)) OVER (Partition by U.ContractID) > U.BasePool THEN 'IN-OVERAGE'
                    --WHEN SUM(SUM(B.TransactionCount)) OVER (Partition by U.ContractID) + (SUM(SUM(B.TransactionCount))  OVER (Partition by U.ContractID)/MonthNum) > U.BasePool THEN DATEADD(MM, 1, GETDATE())
                    ELSE  CASE WHEN MonthNum<1 THEN NULL ELSE CONVERT(VARCHAR(20),DATEADD(MM,CAST(ROUND((U.BasePool - SUM(SUM(B.TransactionCount))  OVER (Partition by U.ContractID)) 
                                /(SUM(SUM(B.TransactionCount))  OVER (Partition by U.ContractID)/MonthNum),0) as Int), GETDATE()),101)

                    --(basepool - sumcontract) / (sumcontract/monthNum ) is the expected months to reach overage
                END 
            END
            END AS  ExpectedDate
4

1 回答 1

3

最大值datetime为“9999-12-31”,因此您可以添加大约 95840 个月getdate() 这会准确地产生您的错误:

select dateadd(month,95841, getdate() )

您在计算要添加的月数时一定犯了错误。

于 2013-04-26T12:13:32.447 回答