HI WELCOME TO KANSIRIS

SQL Server Arithmetic Overflow Error Converting Numeric (Money) to Data Type Numeric

Leave a Comment
Now we will see how we will get this error and fix for this with one example for that write the following query and execute it


DECLARE @decval DECIMAL
SET @decval = 503.12
DECLARE @numval NUMERIC(3,2)
SET @numval = CONVERT(NUMERIC,@decval)
print @numval

When we run above query we will get output like as shown below

Output

 Arithmetic Overflow Error Converting Numeric (Money)to Data Type Numeric
We got this problem because of following lines of query


SET @decval = 503.12
DECLARE @numval NUMERIC(3,2)
SET @numval = CONVERT(NUMERIC,@decval)

Here NUMERIC(3,2) means overall it will allow only 3 digits within that 2 are decimal values but here@decval = 503.12 so overall 5 digits including decimal value but in @numval we are allowing only 3digits including decimal value that’s the reason it’s throwing error.

To fix this problem we need to increase number of digits size in numeric datatype. In NUMERIC(a,b) we need to increase “a” value.

Now we will make modification in above query and write it like as shown below


DECLARE @decval DECIMAL
SET @decval = 503.12
DECLARE @numval NUMERIC(5,2)
SET @numval = CONVERT(NUMERIC,@decval)
print @numval
If we execute above query we will get output like as shown below

Output


SQL Server Fix for Arithmetic Overflow Error Converting Numeric (Money)to Data Type Numeric
I hope it helps you to fix your problem….

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.