// SQL Server error reference

SQL Server error 8115: Arithmetic overflow error converting

A number is too big for the target data type, for example a value over 2,147,483,647 into int, or more digits than a decimal's precision allows.

Error number
8115
Severity
16
Category
Data conversion and truncation
Error message
Arithmetic overflow error converting %ls to data type %ls.

What it means

Each numeric type has a range: tinyint 0 to 255, smallint up to 32,767, int up to 2,147,483,647, and decimal(p, s) at most p digits with s after the decimal point. Converting a value that doesn't fit, explicitly or implicitly, raises 8115. A common surprise is COUNT(*) or SUM() over an int column exceeding the int range on big tables.

Common causes

  • Inserting or converting a value that is larger than the column type allows.
  • SUM() of an int column whose total passes 2,147,483,647; the result type is int.
  • COUNT(*) on more than about 2.1 billion rows (use COUNT_BIG).
  • Converting to a decimal with too few digits, such as 1234.5 into decimal(4,1).
  • An identity column of type int that has run out of values.

How to fix it

  1. Aggregate in a wider type.

    SELECT SUM(CAST(Quantity AS bigint)) AS total, COUNT_BIG(*) AS row_count FROM dbo.OrderLines;
  2. Widen the column to bigint or a larger decimal.

    ALTER TABLE dbo.Metrics ALTER COLUMN Value decimal(18, 4) NOT NULL;
  3. Check how close an identity column is to its limit.

    SELECT IDENT_CURRENT('dbo.Events') AS current_identity;

Reproduce it safely

SELECT CAST(300 AS tinyint);  -- Msg 220 for a constant; with a column or decimal it is 8115:
SELECT CAST(1234.5 AS decimal(4, 1));  -- Msg 8115

Related errors

More data conversion and truncation errors

The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.

// fewer errors, faster fixes

Work on SQL Server in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.