Home SQL Server Errors 8115
Microsoft SQL Server

SQL Server Error 8115

Arithmetic overflow error converting expression to data type

Severity 16 Data Type & Conversion
Applies to: SQL Server 2005 to 2022, Azure SQL Database, Azure SQL Managed Instance
The full message
Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type int.

Why it happens

Error 8115 means a number no longer fits the type it has to live in. Every numeric type has a fixed range: int holds up to about 2.1 billion, smallint up to 32767, and tinyint only up to 255. When a value crosses that boundary, SQL Server cannot store it and raises an arithmetic overflow instead of silently truncating it.

The most common trigger is a SUM() or a multiplication over an int column. Each individual row fits, but the running total does not, because the total is computed in the same int type as the column. The result blows past the 2.1 billion ceiling and the query fails.

Other triggers are converting a big number to a smaller type (bigint to int, or int to smallint or tinyint), an IDENTITY column that has run out of values in its range, and a DECIMAL defined with too few digits of precision or scale to hold the computed value. Severity 16 marks it as a normal, catchable error you can fix in your query.

Examples

A SUM over a large int column overflows int

CREATE TABLE dbo.Sales (
    Amount INT
);

-- Many rows near the int maximum push the total past 2,147,483,647
SELECT SUM(Amount) AS Total FROM dbo.Sales;
Result
Msg 8115, Level 16, State 2, Line 5
Arithmetic overflow error converting expression to data type int.

Converting a value that is too big for tinyint

-- tinyint holds 0 to 255; 300 does not fit
SELECT CAST(300 AS TINYINT) AS Result;
Result
Msg 8115, Level 16, State 2, Line 2
Arithmetic overflow error converting expression to data type tinyint.

A multiplication that exceeds int range

-- Both operands are int, so the product is computed as int and overflows
SELECT 100000 * 100000 AS Product;
Result
Msg 8115, Level 16, State 2, Line 2
Arithmetic overflow error converting expression to data type int.

How to fix it

Cast the column to a bigger type before summing

Widen the result type so the total has room. Cast each value to BIGINT (or DECIMAL) inside the SUM() so the aggregate accumulates in the wide type instead of overflowing int.

SELECT SUM(CAST(Amount AS BIGINT)) AS Total
FROM dbo.Sales;

Widen the target column or variable

If a value keeps outgrowing its column, change the column or variable to a larger type. A bigint holds up to about 9.2 quintillion, which removes the ceiling for most whole-number data.

-- Grow the column from int to bigint
ALTER TABLE dbo.Sales ALTER COLUMN Amount BIGINT;

-- Or size a variable large enough for the result
DECLARE @Total BIGINT = (SELECT SUM(CAST(Amount AS BIGINT)) FROM dbo.Sales);

Use DECIMAL with enough precision for money math

For currency and other exact fractional values, use CAST to a DECIMAL(p,s) whose precision p and scale s are wide enough to hold the computed total, so the sum cannot overflow a narrow type.

SELECT SUM(CAST(Amount AS DECIMAL(19, 2))) AS Total
FROM dbo.Sales;

Reseed or switch an exhausted IDENTITY to bigint

When an IDENTITY runs out of range, either reseed it into unused negative or lower values, or change the column to bigint so it has vastly more values to hand out.

-- Move the identity to bigint for far more headroom
ALTER TABLE dbo.Orders ALTER COLUMN OrderId BIGINT;

-- Or reseed an int identity if a safe range remains
DBCC CHECKIDENT ('dbo.Orders', RESEED, 1);

How to prevent it

Size numeric columns for growth, not just for today. Pick bigint over int when a total or an IDENTITY could realistically climb past 2.1 billion, and give each DECIMAL enough precision and scale to hold the largest value you expect.

Cast aggregates to a wide type as a habit: wrap totals and products in CAST(... AS BIGINT) or a suitable DECIMAL so the calculation never runs in a type too small for the result. Plan IDENTITY ranges up front so a growing table does not exhaust its keys and hit error 8115 in production.

Common questions

Why does SUM overflow even when every row fits in int?

SUM computes the running total in the same data type as the column. Each int value fits, but their total can climb past the int limit of about 2.1 billion, and that total is still an int, so it overflows. Cast the column to BIGINT or DECIMAL inside the SUM so the total is accumulated in a wider type.

What are the ranges of int, bigint and decimal in SQL Server?

An int holds roughly -2.1 billion to 2.1 billion, a smallint holds -32768 to 32767, and a tinyint holds 0 to 255. A bigint holds about -9.2 quintillion to 9.2 quintillion. A decimal(p,s) holds up to p total digits with s of them after the point, so decimal(19,2) can store values up to 17 digits before the decimal point.

How do I fix SQL Server error 8115?

Give the value a type big enough to hold it. Cast aggregates like SUM to BIGINT or DECIMAL, widen the target column or variable, use DECIMAL with enough precision for money math, or move an exhausted IDENTITY to bigint. The message names the target type that overflowed, which tells you what to widen.

Still stuck on a SQL Server error?

Browse the full SQL Server error library, or get hands-on help from an experienced SQL professional.