views:

18

answers:

2

I have a column which has decimal value of 18,8. I was asked to extend it to 18,18 to hold more places after ,.

ALTER TABLE [dbo].[TransakcjeGotowkowe]
ALTER COLUMN TransakcjeGotowkoweKwota decimal (18,18) NULL

Msg 8115, Level 16, State 8, Line 1
Arithmetic overflow error converting numeric to data type numeric.
The statement has been terminated.

I have also tried to do it by GUI. Nothing else changes just want to hold more data after ,.

Is there other way to do this ?

+3  A: 

The Decimal datatype is made up of (precision, scale)

Precision is the total number of digits to the left AND the right of the decimal point.

Scale is the number of digits to the right of the decimal point.

If you want to increase the number of digits to the right to 18 you will need to increase the overall precision. In your case increase it by 10.

So you will need decimal(28,18)

MSDN Article on Precision & Scale

Barry
Lovely :-) I love StackOverflow users :-)
MadBoy
@Martin - Yes I have just re-read the question. I'll update my answer. Thanks
Barry
Having it at 36,18 doesn't affect the values and I can have it that way? It only gives me space for higher values if I ever need it? Or would it be better to keep at 28,18 ?
MadBoy
@MadBoy - `36,18` is 17 bytes per row. `28,18` is 13 bytes. Whether or not that will affect the number of rows that fit on a page depends on the rest of your table definition.
Martin Smith
@MadBoy - You can use which ever you like. If you think that the number will exceed that size then increase it. The main difference, apart from being able to hold bigger numbers, is the storage used. If you use `28,18` it will use 13 storage bytes. If you use `36,18` it will use 17 storage bytes. If storage is an issue then go for the `28,18`
Barry
@Barry - just for my information, I did not exactly understand why we need to increase precision by 10. if scale in source column is 8 and hence data in that column cannot exceed 8. So when moving to column with scale 18, how does it affect?
Sachin Shanbhag
As i understand it decimal (18,8) actually allows storage of 10,8. So if i want to have 10,18 it needs to be (28,18).Hence the increase in precision by 10.
MadBoy
@MadBoy - you are correct.
Barry
@MadBoy, @Barry - Thanks, silly of me that I was thinking differently.
Sachin Shanbhag
+2  A: 

You would need to change it to 28,18 Your current column allows 10 digits to the left of the decimal point.

Changing it to 18,18 would only allow a range between +/-0.999999999999999999

Martin Smith
Thanks for explanation.
MadBoy