I have a column declared as decimal(4,4). Currently it stores 0.0400 as the value. Now I need to update the value stored from 0.0400 to 9.95.I used the following query :
Update <tablename>
set <columnname>= 9.95
where <condition>
When I try to execute, I get the following error : Arithmetic overflow error converting numeric to data type numeric. The statement has been terminated.
Kindly help.
Defining a column as decimal(4,4) is the equivalent of saying
I will have 4 digits in total, of which 4 come after the decimal point
To represent 9.95, you'd need to store it as 9.9500 to satisfy the '4 decimal places' condition. But this now exceeds the 'max 4 digits' condition and so can't be converted.
You'd need at least decimal(5, 4) to store 9.95 as a decimal in this way.
If you write decimal(4,4), what the database hears is:
So a decimal(4,4) can store the range 0.0000 to 0.9999 (and its negative equivalent). But 9.95 is outside that range, so it will return an error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With