Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arithmetic overflow error converting numeric to data type numeric

Status
Not open for further replies.

alwayslrN

IS-IT--Management
Jun 20, 2006
159
US
With the following code

Code:
update nyl_sfp_remit
set net_rate =  case beg_prin_bal when 0 then 0 else (interest * 12/beg_prin_bal)*100 end
[/code/

I get the error mentioned in the subject line.

beg_prin_bal and interest are decimal(12,2) and net_rate is decimal(10,8).

the part of the code that reads
[code]
(interest * 12/beg_prin_bal)

yields a value like .06124984, I want it to return 6.12500000

Thanks for the help
 
I think you need to cast the whole expression using the new percision.
Code:
update nyl_sfp_remit
set net_rate =  convert(decimal(10,8), case beg_prin_bal when 0 then 0 else (interest * 12/beg_prin_bal)*100 end)
or
Code:
update nyl_sfp_remit
set net_rate =  case beg_prin_bal when 0 then 0 else convert(decimal(10,8), (interest * 12/beg_prin_bal)*100) end


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks Jason,

I had actually tried the latter and it did not work. Also tried your first option and it did not work either.
 
Interesting, when I use the expression in a select statement I do not receive that error. It only happens when attempting to do an update.
 
I think I figured out my problem. It seems the calculation yields a result of decimal(11,8) in some instances. Not good.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top