On this page
Why it happens
Error 245 means SQL Server attempted a conversion from a character type such as varchar to a numeric type such as int, and at least one value could not be turned into a number. The message quotes the exact offending value, for example the varchar value 'N/A', which is your fastest clue to the bad row.
The conversion can be explicit, when you write a CAST or CONVERT, or implicit, when SQL Server converts automatically because you compared or combined two different types. Data type precedence decides the direction: int has higher precedence than varchar, so when the two meet SQL Server converts the text to a number, and a value like 'N/A' makes that conversion fail.
Common triggers are comparing or joining a varchar column to an int column, running a CAST or CONVERT over dirty data, using + to glue a number onto text instead of a string function, or a WHERE clause that mixes types. The error is severity 16, a normal statement level error you can catch and fix.
Examples
Implicit conversion in a WHERE comparison
-- Code is varchar and contains values like 'N/A'.
-- Comparing it to an int forces SQL Server to convert the text.
SELECT * FROM dbo.Products WHERE Code = 100;
Msg 245, Level 16, State 1, Line 3 Conversion failed when converting the varchar value 'N/A' to data type int.
Explicit CAST of a non-numeric value
SELECT CAST('N/A' AS int) AS Result;
Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value 'N/A' to data type int.
Concatenating a number to text with +
-- The + operator makes SQL Server convert the text 'Order ' to int
-- because the other side is an int.
SELECT 'Order ' + 100 AS Label;
Msg 245, Level 16, State 1, Line 3 Conversion failed when converting the varchar value 'Order ' to data type int.
How to fix it
Use TRY_CAST or TRY_CONVERT to fail safely
TRY_CAST and TRY_CONVERT return NULL instead of raising an error when a value cannot be converted, so a single bad row no longer stops the whole query. This is the quickest fix when you must keep comparing text to a number. See the CAST and CONVERT functions for the underlying behaviour.
-- Rows where Code is not a number become NULL and drop out
SELECT * FROM dbo.Products WHERE TRY_CAST(Code AS int) = 100;
Clean or filter out the non-numeric data
If a column should only hold numbers, exclude the rows that do not before converting them. A pattern check keeps only all-digit values so the conversion never sees 'N/A'.
SELECT * FROM dbo.Products
WHERE Code NOT LIKE '%[^0-9]%'
AND CAST(Code AS int) = 100;
Fix the type mismatch so both sides match
Implicit conversions are the most common cause. Compare like with like: quote the literal so SQL Server compares text to text, or store the column as the correct numeric type so no conversion is needed at all.
-- Compare varchar to varchar, no conversion happens
SELECT * FROM dbo.Products WHERE Code = '100';
Use CONCAT() instead of + to build strings
The + operator converts everything to the highest precedence type, which turns text into a number and fails. CONCAT() converts every argument to a string safely, so numbers join onto text without error.
SELECT CONCAT('Order ', 100) AS Label; -- returns 'Order 100'
How to prevent it
Store numbers in numeric columns such as int or decimal, not in varchar. When the column type matches the data, SQL Server never has to guess a conversion and error 245 cannot happen. Validate input at the application layer or with a CHECK constraint so non-numeric text never lands in a column meant to hold numbers.
Avoid implicit conversions in joins and WHERE clauses: make both sides the same type, and reach for CAST, CONVERT, or their TRY_ variants when you must convert deliberately. If you keep hitting related conversion failures, see error 8114 which comes from the same family of type mismatches.
Common questions
What is the difference between CAST and TRY_CAST?
CAST raises error 245 and stops the query when a value cannot be converted, while TRY_CAST returns NULL for that value and lets the query continue. Use CAST when every value is known to be convertible and TRY_CAST when the data might contain values like N/A that would otherwise fail.
Why did my query work for months and then suddenly throw error 245?
The query only fails when a row contains a value that cannot be converted. It worked while every value in the column was numeric, then someone inserted text such as N/A or an empty string, and the next run of the implicit conversion hit that bad row. The message quotes the exact value so you can find and fix the offending record.
How do I find which row is causing error 245?
The message names the bad value, for example the varchar value N/A. Run SELECT * FROM YourTable WHERE Column LIKE %[^0-9]% to list every row whose value is not all digits, then clean or remove those rows.