Fix “Arithmetic overflow error converting int to data type numeric” in SQL Server

If you’re receiving error Msg 8115, Level 16, Arithmetic overflow error converting int to data type numeric in SQL Server, it’s probably because you’re performing an operation that results in a data conversion error due to an out of range value.

This will often happen when you try to convert a number to a different data type, but it’s out of the accepted range for the new data type.

Example of the Error

Here’s an example of code that produces the error:

SELECT CAST(275 AS DECIMAL(3, 2));

Result:

Msg 8115, Level 16, State 8, Line 1
Arithmetic overflow error converting int to data type numeric.

In this case I was trying to convert an integer to a decimal.

But my mistake is that I only allowed for a precision of 3 for the resulting decimal value. This precision isn’t sufficient for the value that would be produced by this operation (which would be 275.00).

The Solution

The problem is easily fixed:

SELECT CAST(275 AS DECIMAL(5, 2));

Result:

275.00

All I did was increase the precision argument to a more sufficient value.

Specifically, I increased it from 3 to 5.

If I was expecting larger integers to come through (for example, if the integer was in a database column), then I would need to increase the precision so that it could handle the larger values.

Just to be clear, precision is the maximum total number of decimal digits to be stored. This number includes both the left and the right sides of the decimal point. The precision must be a value from 1 through the maximum precision of 38. The default precision is 18.

Same Error in Different Scenarios

The same error (Msg 8115) can occur (with a slightly different error message) when you use a function such as SUM() on a column, and the calculation results in a value that’s outside the range of the column’s type. See Fix “Arithmetic overflow error converting expression to data type int” in SQL Server to fix this.

And the same error (Msg 8115) can also occur (with a slightly different error message) when you try to insert data into a table when its IDENTITY column has reached its data type’s limit. See Fix: “Arithmetic overflow error converting IDENTITY to data type…” in SQL Server for how to fix this.