Can't Figure out Arithmetic Overflow Error

Doug 1 Reputation point
2020-10-23T16:00:25.343+00:00

I have been receiving this error.

Msg 8115, Level 16, State 2 Line 182
Arithmetic Overflow Error converting expression to data type int.

Any Help is greatly appreciated

SELECT
 ot.Unitname
 ,LOWER(REPLACE([Unitname],', ',' '))  AS [Location]
 ,DATEPART(YEAR, (ot.[CheckCloseDateTime])) AS 'Year'
 ,DATEPART(MONTH, (ot.[CheckCloseDateTime])) AS 'Month'
 ,DATEPART(DAY, (ot.[CheckCloseDateTime])) AS 'Day'
 ,DATEPART(HOUR, (ot.[CheckCloseDateTime])) AS 'Hour'
 ,DATEPART(MINUTE, (dateadd(minute, datediff_big(minute,0,(ot.[CheckCloseDateTime])) / 15 * 15, 0))) AS 'Minute'
 ,CAST(COUNT(*) * -1 AS BIGINT)  AS 'Tables'
 ,CAST(SUM(COALESCE(NULL,ot.[CheckGrossAmount],0)) AS BIGINT)  AS 'Amount'

INTO #Temp5 
FROM @InitialChecks ot

GROUP BY  
 ot.Unitname 
 ,DATEPART(YEAR, (ot.[CheckCloseDateTime]))
 ,DATEPART(MONTH, (ot.[CheckCloseDateTime]))
 ,DATEPART(DAY, (ot.[CheckCloseDateTime]))
 ,DATEPART(HOUR, (ot.[CheckCloseDateTime]))
 ,DATEPART(MINUTE, (dateadd(minute, datediff_big(minute,0,(ot.[CheckCloseDateTime])) / 15 * 15, 0)))
ORDER BY  
 ot.Unitname
 ,'Year'
 ,'Month'
 ,'Day'
 ,'Hour'
 ,'Minute'
Azure SQL Database
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.