Saturday, November 1, 2008

SQL can't average two large integers

SQL is unable to average two integers, presumably because their sum is greater than maxint:-

select
avg(col)
from (
select 2147483647 as col
union all
select 2147483647
) t



fails with:

Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type int.

Where 2147483647 is the max value of an int datatype.

No comments: