# SQLCODE -413: Overflow during numeric conversion

Source: https://wndsoftware.com/mainframe-errors/sqlcode-413

### SQLCODE -413: Overflow during numeric conversion

SQLCODE -413 (SQLSTATE 22003) means an overflow or underflow happened while Db2 converted a number from one numeric data type to another, for example a large DECIMAL value cast to SMALLINT. The statement fails and nothing is changed.


#### Other names for this code

Also written as `SQL -413`, `SQLCODE=-413`, `SQLCODE = -413`, `db2 -413`, `sqlstate 22003`, `SQL0413N`, `db2 overflow numeric conversion`, `SQL0413`, `overflow or underflow occurred during numeric data type conversion`.


### What it means

Db2 converts numbers between types all the time, in an explicit CAST, in functions such as SMALLINT, INTEGER, BIGINT and DECIMAL, and when it brings values of different types together. Each target type has a range. When the value being converted is too big for the target, or too small for a floating-point target to hold, Db2 can't represent it and stops the statement with -413.

Several codes describe numbers that don't fit, and the right one tells you where to look. -413 is a conversion inside SQL. [-406](https://wndsoftware.com/mainframe-errors/sqlcode-406) is a calculated value stored in a column too small for it. [-802](https://wndsoftware.com/mainframe-errors/sqlcode-802) is an overflow in the arithmetic itself, such as a multiplication or a SUM. -304 is a value returned to a host variable that is too small.


### Common causes

- A CAST or conversion function narrows a value that is too large, for example `SMALLINT(QTY)` when some rows hold more than 32,767, or `INTEGER(TOTAL)` on a BIGINT total.
- `DECIMAL(expr, 5, 2)` or `CAST(expr AS DECIMAL(5,2))` is applied to values of 1,000 or more.
- A floating-point or DECFLOAT value far outside the DECIMAL range is converted to DECIMAL.
- Data has grown past what a conversion in an old query assumed, for example IDs that used to fit in INTEGER.
- A bad row, such as a sentinel value of all nines, slips into data that is normally small.


### How to find the problem

- List every explicit CAST and conversion function in the statement, and note the target type of each.
- Check the range of the source data with `SELECT MIN(QTY), MAX(QTY) FROM ...` using the same WHERE clause.
- Find the rows that break the limit, for example `SELECT ORDER_NO, QTY FROM ... WHERE ABS(QTY) > 32767`.
- If the statement has no explicit conversion, look at expressions that mix numeric types and at the types of host variables passed in.


### How to fix it

- Convert to a type big enough for the data, such as INTEGER or BIGINT instead of SMALLINT, or a DECIMAL with more digits.
- Guard the conversion with a CASE expression that handles out-of-range values in the way the business wants.
- Fix bad rows at the source if the large values shouldn't exist.
- Review older queries and copybooks that assume small values whenever a key or counter grows.


### IBM documentation

[IBM documentation: -413](https://www.ibm.com/docs/en/db2-for-zos/13.0.0?topic=codes-413). Use the documentation for your installed release.

[Report a correction to WND Software](https://wndsoftware.com/contact#message).

Technical reviewer: [Albert Joseph](https://wndsoftware.com/authors/albert-joseph), WND Software.

Last reviewed 2026-10-18 by the WND Software team. Written in our own words. For the full reference, check IBM’s Db2 for z/OS documentation for your release.


### Related codes

[SQLCODE -406 Derived numeric value out of range Read →](https://wndsoftware.com/mainframe-errors/sqlcode-406)
[SQLCODE -802 Arithmetic overflow or divide by zero Read →](https://wndsoftware.com/mainframe-errors/sqlcode-802)
[SQLCODE +304 Value out of range for host variable (warning) Read →](https://wndsoftware.com/mainframe-errors/sqlcode-plus-304)
[SQLCODE -304 Value out of range for host variable Read →](https://wndsoftware.com/mainframe-errors/sqlcode-304)
[SQLCODE -420 String argument not acceptable to function Read →](https://wndsoftware.com/mainframe-errors/sqlcode-420)

### Questions


#### What is the difference between -413 and -406?

-413 is an overflow while converting between numeric types inside the SQL. -406 is a calculated value that doesn't fit the column it's being stored in.


#### Can -413 come from a FETCH into a host variable that is too small?

That case is normally reported as -304, or +304 with the indicator set to -2 when the program supplied an indicator variable.


#### Is it the same on Db2 for LUW?

Yes. Db2 for LUW reports SQL0413N with SQLSTATE 22003 for an overflow during numeric data type conversion.

[Db2 SQLCODEs](https://wndsoftware.com/mainframe-errors/db2-sqlcodes) · [SQLCODE -408](https://wndsoftware.com/mainframe-errors/sqlcode-408) · [SQLCODE -420](https://wndsoftware.com/mainframe-errors/sqlcode-420)

[← All error codes](https://wndsoftware.com/mainframe-errors/)
