3

I'm getting an "Arithmetic overflow error converting expression to data type int" error when running a simple aggregate function (see code below). As I throttle back the date range, I can see that the results is in fact exceeding the INT data type limit...I've tried casting the whole expression into a BIGINT w/o success. Anyone know how I can resolve this issue?

All 3 of these queries throw the same above mentioned error:

Select  (SUM(ACDTalkTimeInSec) + SUM(TotAcwTimeInSec) + SUM(HoldTimeInSec)) as AHT
From ColTelephony.dbo.vwACDSkillCombined acd
Where WorkDte between '1/2/2018' AND '10/5/2018'

Select  CAST(Cast(SUM(ACDTalkTimeInSec) AS BIGINT) + CAST(SUM(TotAcwTimeInSec) AS BIGINT) + CAST(SUM(HoldTimeInSec) AS BIGINT) AS BIGINT) as AHT
From ColTelephony.dbo.vwACDSkillCombined acd
Where WorkDte between '1/2/2018' AND '10/5/2018'

Select  Cast(((SUM(ACDTalkTimeInSec) + SUM(TotAcwTimeInSec) + SUM(HoldTimeInSec))) AS BIGINT) as AHT
From ColTelephony.dbo.vwACDSkillCombined acd
Where WorkDte between '1/2/2018' AND '10/5/2018'
2
  • 4
    You need to cast before you sum, not after. Commented Oct 9, 2018 at 17:29
  • 1
    Thank! Worked perfect! I hate when the answer is so simple like that lol. Please post as answer and I will mark it as such. Thanks again! Commented Oct 9, 2018 at 17:33

1 Answer 1

2

SMor answered it in the comments, but here is the sql:

Select SUM(CAST(ACDTalkTimeInSec AS BIGINT)) + SUM(CAST(TotAcwTimeInSec AS BIGINT)) 
    + SUM(CAST(HoldTimeInSec AS BIGINT)) as AHT
From ColTelephony.dbo.vwACDSkillCombined acd
Where WorkDte between '1/2/2018' AND '10/5/2018'

If SMor posts their answer then accept that. I did not test the code so pardon any typos.

Sign up to request clarification or add additional context in comments.

1 Comment

I was searching for the same issue. Thanks @Michael

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.