SQL Server:将表达式转换为数据类型int的算术溢出错误

前端之家收集整理的这篇文章主要介绍了SQL Server:将表达式转换为数据类型int的算术溢出错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我收到这个错误

msg 8115,level 16,state 2,line 18
Arithmetic overflow error converting expression to data type int.

用这个SQL查询

DECLARE @year VARCHAR(4);                       
DECLARE @month VARCHAR(2);                      

-- START OF CONFIGURATION SECTION                       
-- THIS IS THE ONLY SECTION THAT SHOULD BE MODIFIED                     
-- SET THE YEAR AND MONTH PARAMETERS                        

SET @year = '2013';                     
SET @month = '3';  -- 1 = January.... 12 = Decemeber.                       

-- END OF CONFIGURATION SECTION                     

DECLARE @startDate DATE                     
DECLARE @endDate DATE                       
SET @startDate = @year + '-' + @month + '-01 00:00:00';                     
SET @endDate = DATEADD(MONTH,1,@startDate);                       

SELECT                          
    DATEPART(YEAR,dateTimeStamp) AS [Year],DATEPART(MONTH,dateTimeStamp) AS [Month],COUNT(*) AS NumStreams,[platform] AS [Platform],deliverableName AS [Deliverable Name],SUM(billableDuration) AS NumSecondsDelivered                      
FROM                            
    DeliveryTransactions                        
WHERE                           
    dateTimeStamp >= @startDate                     
AND dateTimeStamp < @endDate                        
GROUP BY                            
    DATEPART(YEAR,dateTimeStamp),[platform],deliverableName                       
ORDER BY                            
    [platform],DATEPART(YEAR,deliverableName

解决方法

SUM(billableDuration)的问题是?要找出来,尝试评论该行,看看它是否有效.

这可能是总和超过最大int.如果是这样,请尝试用SUM(CAST(billableDuration AS BIGINT))替换它.

原文链接:https://www.f2er.com/mssql/75153.html

猜你在找的MsSQL相关文章