Skip to main content
Participant
May 5, 2006
Answered

Sum exceeds 32,767

I am trying to find the average call length in our database of support calls by using "SUM(calltime) AS time_total" and then dividing that by the number of incidents. The field I am searching on, calltime, is short integer.

If time_total is more than 32,767, it returns either an error or a negative value depending upon the version of the database I'm using. I understand why this is happening, but can't figure out how to fix it. I can't change the database; it's enormous. Is there some way to specify that time_total needs to be a long integer?
This topic is closed to new replies. Start a new post to keep the conversation going.
paross1Correct answer
Participating Frequently
May 5, 2006
If you can't alter the datatype in the database, you might try casting calltime as an int or bigint, something like

SUM(CAST(calltime AS int)) AS time_total
or perhaps
CAST(SUM(calltime) AS int) AS time_total

Phil

6 replies

Inspiring
May 5, 2006
Database size is not the obstacle in this case (hopefully you have Oracle or SQL Server). You (or your DBA)could increase the column size to long integer without loosing data.
Translate
paross1Correct answer
Participating Frequently
May 5, 2006
If you can't alter the datatype in the database, you might try casting calltime as an int or bigint, something like

SUM(CAST(calltime AS int)) AS time_total
or perhaps
CAST(SUM(calltime) AS int) AS time_total

Phil
Translate
Ellen_KAuthor
Participant
May 5, 2006
Thanks, you were writing that as I was typing my other reply. Yes, that's the direction I was trying to go in. I am unfamiliar with CAST but will play around with that.

Thanks again!
Translate