3

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.

4 Answers 4

5

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.

Sign up to request clarification or add additional context in comments.

Comments

1

If you write decimal(4,4), what the database hears is:

  • There are four digits total
  • All four of them are behind the decimal separator

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.

Comments

1

I had similar issue few years ago, here is my understanding.

Decimal(TotalDigitsIncludingDecimal,DecimalPlaces)

Eg: Value = 50.05 declare Decimal(4,2) Eg: Value = 5000.0005 declare Decimal(8,4)

Comments

1

Decimal(6,2) means:

At most 4 digits to the left of the decimal point, since you can have 2 to the right of the decimal point. (even if you don't see them, or use them)

It is VERY wrong to say "you can have 6 digits total". 12345 is less than 6 digits total. But it'll overflow.

I'm not sure why SQL didn't just make it "Decimal(left, right)" and you would instantly see the limits you can store there.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.