Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Arithmetic overflow error converting varchar to data type numeric – SQL Server

I have a column with datatype numeric(18,3). The user can enter decimal numbers as well. I have set the max length of this text box to 18 but when I type 777777777777777777, I get this error

Arithmetic overflow error converting varchar to data type numeric

Can someone explain me why I am getting this error?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Because numeric(18,3) means: 18 digits in total, thereof 3 after the decimal point – so you only get 15 digits before the decimal point.

Entering 18 digits (before the decimal point) will obviously cause an overflow!

If you really need 18 digits before the decimal point, you need to define your column as numeric(21,3)

ALTER TABLE dbo.TableName 
    ALTER COLUMN MinimumValue NUMERIC(21, 3)

For more details, read the fabulous docs

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading