This SQL Server error means a text value cannot fit into the target numeric precision or scale during conversion.
When you see the “Arithmetic Overflow Error Converting VARCHAR To Data Type NUMERIC” message in SQL Server, it usually appears without much context and stops your query, import, or report cold. Behind that short line is a very specific mismatch between text data in a varchar column and the numeric or decimal definition you are converting into. Once you understand how precision and scale work, and how SQL Server picks target numeric types, the error becomes predictable and fixable instead of mysterious.
This guide breaks down what the error actually means, the most common ways it appears, and safe patterns that let you clean data, adjust column definitions, and guard future code. The goal is simple: help you find the bad rows fast, change the right numeric types, and keep conversions safe in production.
Why Arithmetic Overflow Happens When Converting VARCHAR To Numeric
Every numeric or decimal type in SQL Server is defined by two numbers: precision and scale. Precision is the total number of digits the value can store, and scale is how many of those digits sit to the right of the decimal point. For instance, a value with precision 5 and scale 2 can hold five digits in total, with two after the decimal, such as 123.45.
When you convert from varchar to numeric(p,s), SQL Server parses the string and checks whether the resulting number fits inside that precision and scale. If the value has more digits than the precision allows, the conversion overflows and the engine throws the arithmetic overflow error instead of silently truncating. This also applies when expressions mix varchar values with numeric literals, because SQL Server often chooses the smallest numeric type that looks large enough for the literal and then promotes other operands to match that choice.
There are two broad ways the overflow happens during a varchar conversion:
- Too many digits — The parsed number has more total digits than the precision you asked for, even if it seems “close” to the limit.
- Too large integer part — The part to the left of the decimal already fills the precision budget, so there is no room for the fractional part that the target scale expects.
Take numeric(3,2). This type can hold three digits in total, two of them after the decimal. The largest value it can store is 9.99. If you convert the string '10.00' into numeric(3,2), the integer part needs two digits and the scale still needs two more digits, which adds up to four. That is one digit more than the precision allows, so the conversion fails with arithmetic overflow.
Arithmetic Overflow Error Converting VARCHAR To Data Type NUMERIC In Real Queries
The error text always looks roughly the same, but the trigger often sits in everyday T-SQL patterns. Knowing the patterns helps you narrow down the root cause quickly, even if the reported line number sits in a long stored procedure.
Some common places where the full conversion error shows up are:
- INSERT or UPDATE into numeric columns — A
varcharsource column or variable is being converted to a targetnumericcolumn that cannot hold the largest values being inserted. - Computed expressions in SELECT lists — Expressions that mix numeric literals and
varcharvalues lead SQL Server to pick a small numeric type for the result, and a wide string value overflows that type. - CAST/CONVERT in ETL or reports — Data imports that treat incoming values as
varcharfirst, then cast tonumeric, can fail when a single row contains a larger-than-expected amount, rate, or balance. - JOIN or WHERE conditions — Comparing a
varcharcolumn to a numeric expression or literal can trigger an implicit conversion to a narrow numeric type.
In many production databases, numeric columns start life with a small precision such as numeric(9,2) because early data fits inside that range. Over time, someone loads a value with more digits, leading to the first overflow event. Since the error message only mentions the conversion type and not the exact row, you need a repeatable way to locate the offending values.
How To Track Down Problem Rows Safely
Once you know a conversion fails, the next task is to find the rows that trigger it without stopping the query itself. SQL Server provides TRY_CONVERT and TRY_CAST for this exact case. These functions attempt the conversion and return NULL when conversion fails, instead of raising an error.
You can use this to scan a varchar column and isolate values that do not fit a given numeric definition:
SELECT *
FROM dbo.Payments
WHERE TRY_CONVERT(numeric(9,2), AmountText) IS NULL
AND AmountText IS NOT NULL
AND LTRIM(RTRIM(AmountText)) <> '';
This pattern returns rows where AmountText cannot be converted to numeric(9,2). That includes values with non-numeric characters, values that are too wide for the chosen precision, and values where the decimal layout does not match the scale you asked for.
To focus on pure overflow cases for a known numeric definition, you can mix TRY_CONVERT with simple length checks:
SELECT AmountText
FROM dbo.Payments
WHERE TRY_CONVERT(numeric(9,2), AmountText) IS NULL
AND LEN(REPLACE(AmountText, '.', '')) > 9;
This variant looks for values whose digits (ignoring the decimal point) exceed the precision. That gives you a quick picture of just how far the data reaches, which feeds into the next step: picking safer numeric definitions.
Choosing Safe NUMERIC Precision And Scale
To avoid arithmetic overflow, the target numeric(p,s) definition must match the largest value you expect to store. Precision is the maximum total number of digits, while scale is the number of digits to the right of the decimal point. SQL Server allows a precision up to 38 for numeric and decimal.
A handy way to think about it is:
- Digits left of decimal =
precision − scale - Max value ≈ a string of
(precision − scale)nines, followed by a decimal point andscalenines
The table below gives a few reference points that often show up in financial and reporting work:
| Numeric Definition | Digits Left Of Decimal | Largest Storable Value |
|---|---|---|
numeric(9,2) |
7 | 9,999,999.99 |
numeric(12,2) |
10 | 9,999,999,999.99 |
numeric(18,4) |
14 | 999,999,999,999,99.9999 |
Before you change a column or variable, run a quick scan to see the widest real value you have:
SELECT MAX(TRY_CONVERT(decimal(38,4), AmountText)) AS MaxAmount
FROM dbo.Payments;
Once you know the maximum value and the number of decimal places you truly need, you can pick a precision and scale with some headroom above that maximum. If a column is already numeric(5,2) and you see values like 1000.00, you can move to numeric(6,2) or higher, because numeric(5,2) tops out at 999.99.
After you settle on a safer definition, use ALTER TABLE or variable changes in procedures to update the type. Make sure you test on a copy of production data so you do not discover a second, even larger value after the deployment.
Cleaning Varchar Input Before Conversion
Sometimes the arithmetic overflow error is a side effect of messy text formatting rather than legitimate large values. Data feeds that include currency symbols, thousand separators, or stray characters can force SQL Server to interpret the number differently than you expect. Cleaning the text before conversion reduces surprises and keeps your numeric definitions smaller.
Here are some safe clean-up steps that you can combine in a view, staging table, or inline expression:
- Trim spaces — Wrap values in
LTRIM(RTRIM())so leading or trailing spaces do not confuse length checks. - Strip currency symbols — Remove characters like
$,£, or brackets that represent negative values in some exports. - Normalize separators — Replace commas that act as thousand separators and ensure the decimal point marker is consistent with your region and data feed.
- Filter bad characters — Use
TRY_CONVERTto discard rows that still refuse to convert even after cleaning, and route them into an error table for review.
For repeatable imports, it is often worth building a small staging table where the source values arrive as raw varchar, a second column stores a cleaned version, and a third column stores the converted numeric value using TRY_CONVERT. That gives you a clear audit trail when a new malformed value appears later.
Defensive Patterns To Prevent Future Overflows
Once you have cleaned existing data and adjusted the numeric definitions, you can reduce the chance of seeing the arithmetic overflow error again by building a few safety checks into your code. These checks add a tiny amount of logic while saving time during future imports and report runs.
- Use TRY_CONVERT at ingestion — Convert incoming
varcharamounts withTRY_CONVERTin staging, log rows where the result isNULL, and only move clean rows into final tables. - Validate ranges in stored procedures — When procedures accept string parameters for amounts, dates, or counts, convert them with
TRY_CONVERTand raise a friendly error if the result isNULLor out of range, instead of letting an implicit conversion fail later. - Standardize numeric types — Agree on a small set of
numeric(p,s)shapes for common concepts such as money, rates, and quantities, and reuse them across tables to avoid narrow one-off definitions. - Watch for implicit conversions — When joining
varcharand numeric columns, cast explicitly on the side where you control the range, so SQL Server does not pick a narrow numeric type based only on a literal.
The next time “Arithmetic Overflow Error Converting VARCHAR To Data Type NUMERIC” appears, you can follow a consistent script: reproduce the failing query, swap direct conversions for TRY_CONVERT to isolate bad rows, scan the data to see the real numeric range, pick a safer precision and scale, and update the schema or code in a controlled change. Over time, these habits make your numeric conversions predictable, your ETL flows calmer, and your logs far cleaner.
