Numeric Overflow While Sum

UDA
Enthusiast

Numeric Overflow While Sum

Hi All,

I tried to to do sum for a column where I am getting numeric overflow error.

Eg:
----
Sel
Sum(Col1) from Tab1 group by1 col2;

Where Col1 is an integer.

I tried to caste it as

Sel
Cast(Sum(Col1) as decimal(38,0))
from tab1 group by col2;

But I am still facing the error.Can someone help me out?

Thanks,
Ashok.
2 REPLIES
Enthusiast

Re: Numeric Overflow While Sum

You are still adding it up as an integer and then casting the sum.You need to cast the individual values and the add them up.

So:

Sel
sum(Cast(Col1 as decimal(38,0)))
from tab1 group by col2;
Enthusiast

Re: Numeric Overflow While Sum

Thank you very much Jimm.It worked.