Medium severitydata integrity
SQL Server Error:
8115
What does this error mean?
SQL Server raises error 8115 when an expression produces a numeric result that exceeds the range of its target data type. The full message reads: 'Arithmetic overflow error converting expression to data type [type].' This typically surfaces during SUM(), AVG(), or multiplication operations on INT, SMALLINT, or DECIMAL columns where the accumulated value outgrows the type's boundary (e.g., INT maxes out at 2,147,483,647). In data pipelines, 8115 often appears inside ADF Copy Activities, stored procedure steps, or Power BI DirectQuery refreshes — not during development, but weeks or months later when row counts or values cross a threshold. The query fails entirely; no partial result is returned.
Common causes
- 1SUM() or COUNT() on an INT column exceeds 2,147,483,647 — common in fact tables that grow past ~2 billion rows or hold large monetary values stored as INT cents.
- 2DECIMAL(p,s) precision is too narrow for a computed result. Example: DECIMAL(10,2) maxes out at 99,999,999.99; a SUM over a large dataset crosses that boundary.
- 3Implicit type conversion during INSERT...SELECT or MERGE when the source expression yields a wider type than the target column allows.
- 4A CAST or CONVERT in a WHERE clause or JOIN condition silently narrows a value — e.g., CAST(BIGINT_col AS INT) in a view that ADF queries.
- 5Date arithmetic produces a datetime outside SQL Server's valid range (1753-01-01 to 9999-12-31), for example DATEADD(DAY, large_offset, '2020-01-01') with dirty offset values.
How to fix it
- 1Step 1: Identify the failing expression. Run the query in SSMS with SET ANSI_WARNINGS ON and check the error message for the target type. The execution plan's Compute Scalar or Stream Aggregate operator shows where overflow occurs.
- 2Step 2: Widen the aggregation input before it overflows: SELECT SUM(CAST(amount AS BIGINT)) FROM sales; — casting inside SUM prevents overflow during accumulation.
- 3Step 3: For DECIMAL overflows, increase precision in the expression: SELECT SUM(CAST(unit_price AS DECIMAL(18,2))) FROM order_lines; — or ALTER the column: ALTER TABLE order_lines ALTER COLUMN unit_price DECIMAL(18,2);
- 4Step 4: Find all INT columns at risk of overflow: SELECT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE DATA_TYPE = 'int' AND TABLE_SCHEMA = 'dbo'; — cross-reference with tables that hold growing counters or financial totals.
- 5Step 5: For date overflows, filter invalid dates before calculation: DELETE FROM staging.events WHERE event_date < '1753-01-01' OR event_date > '9999-12-31'; — or use TRY_CONVERT(datetime, event_date) IS NOT NULL in a WHERE clause.
- 6Step 6: In ADF, if a Copy Activity triggers 8115, open the pipeline run → Activity output → check the 'errors' array for the exact SQL statement. Fix the source query or add a pre-copy script that casts columns.
- 7Step 7: After fixing, add a data quality check to your pipeline that asserts MAX(col) < threshold. Example: IF (SELECT MAX(amount) FROM sales) > 2000000000 THROW 50001, 'amount approaching INT overflow', 1;
Example log output
2026-05-11T06:15:03.412Z [ERROR] Activity 'sp_load_daily_revenue' failed: Msg 8115, Level 16, State 2, Line 14
Arithmetic overflow error converting expression to data type int.
2026-05-11T06:15:03.418Z [ERROR] Pipeline 'pl_nightly_warehouse' run 9a3f2c10-4b1a-8e4d-0d5e-6f7a8b9c3a7f terminated with status Failed