We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

# Arithmetic overflow error converting expression to data type smallmoney

on
Medium Priority
834 Views
I have a stored procedure that has been running fine for serveral month, and appears to run fine for most cases for rows processed, but is blowing up with the arithmentic overflow consistently at the same point. The function calculated interest and adds interest and contributions to a balance for some number of contributions (payments). Here is the code:

declare  @amount smallmoney,
@balance smallmoney,
@interest smallmoney

set @balance = @balance + @interest + @amount

To debug, I print balance, interest and amount for each iteration. When they have the following values:

balance: 213882.22
interest: 35.56
amount: 6003.12

I get the error:

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

Note, the "@balance = @balance + @interest + @amount" is line 160.

None of these values seem to exceed the smallmoney range. What's up? This is preventing us from printing payroll checks!!!!
Comment
Watch Question

## View Solution Only

Commented:
Hi,

Min and max for smallmoney is - 214,748.3648 to 214,748.3647 so you have to change @balance to another type.

/peter

Not the solution you were looking for? Getting a personalized solution is easy.

Commented:
And the total that you're trying to assign to @balance is 219,920.9.
CERTIFIED EXPERT

Commented:
Pivar is correct. Can you assign @balance as money instead of smallmoney?

Commented:
I changed it to decimal(14,5), but money would have probably worked too. I don't know why, but I was reading the smallmoney limit as 214 million, not 214 thousand. My bad. Thanks!
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile