Skip to content
Microsoft SQL Server

SQL Server Error 245

Conversion failed when converting the varchar value to data type int

Applies to: All supported SQL Server versions (2016 to 2025), Azure SQL Database, Azure SQL Managed Instance
Last technically reviewed 23 October 2026 on SQL Server 2025 (17.0.1145.4)
The full message
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'N/A' to data type int.
Other forms of this message
Unicode source column or literal
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the nvarchar value 'abc' to data type int.
A decimal string converted to int
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value '12.5' to data type int.
Error number
245
Severity
16 (user-correctable error)
State
1
Product
Microsoft SQL Server Database Engine
Versions
All supported SQL Server versions (2016 to 2025), Azure SQL Database, Azure SQL Managed Instance
Last reviewed
23 October 2026

What it means

Error 245 means SQL Server tried to turn a text value into an integer and the text quoted in the message is not a valid whole number.

Read the message from left to right: the source type (varchar or nvarchar), the exact value that failed in quotes, and the target type. The quoted value is the row you are looking for. The conversion can be explicit, through CAST or CONVERT, or implicit, when an expression mixes text and an integer.

Implicit conversions follow data type precedence: int ranks above varchar, so when the two meet in a comparison, a +, a CASE expression or a UNION, SQL Server converts the text side to int. One row holding N/A, a decimal such as 12.5 or a stray letter is enough to stop the statement at severity 16, often after some rows have already been returned.

Common causes

  • A varchar column compared or joined to an int column or an integer literal, while some rows hold non-numeric text.
  • CAST or CONVERT to int over data that contains placeholders such as N/A, blanks with letters, or decimals like 12.5.
  • Building a string with + where one operand is a number, so SQL Server tries to turn the text into int.
  • A CASE expression or UNION whose branches return text in one place and an integer in another.
  • A pattern check (for example NOT LIKE '%[^0-9]%') placed next to a CAST in the WHERE clause, expecting it to run first.

Diagnose it

Read-only These queries only read metadata and dynamic management views. They do not change data, permissions or configuration, so they are safe to run first.

List the values that will not convert

TRY_CAST returns NULL instead of failing, so it can scan every row and show all the offenders, not only the first one in the message.

SELECT id, Code
FROM dbo.Products
WHERE Code IS NOT NULL
  AND TRY_CAST(Code AS int) IS NULL;
What to look for

Every row whose text is not a whole number. An empty result means the conversion error comes from another column or expression.

Check the data types on both sides of the comparison

SELECT OBJECT_NAME(c.object_id) AS table_name, c.name AS column_name, t.name AS data_type, c.max_length
FROM sys.columns AS c
JOIN sys.types AS t ON t.user_type_id = c.user_type_id
WHERE c.object_id IN (OBJECT_ID(N'dbo.Products'), OBJECT_ID(N'dbo.Orders'))
ORDER BY table_name, c.column_id;
What to look for

A text column (varchar, nvarchar, char) matched against an int column or literal is where the implicit conversion happens.

How to fix it

Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.

Compare like with like

Read-only

When the column is text, compare it to text. Quoting the literal removes the conversion entirely, and an index on the column can still be used.

SELECT * FROM dbo.Products WHERE Code = '100';

Use TRY_CAST or TRY_CONVERT when you must convert

Read-only

TRY_CAST returns NULL for a value it cannot convert, so the bad rows simply drop out of the comparison. This is also the safe replacement for a pattern check beside a CAST: SQL Server does not promise to evaluate WHERE conditions in the order you write them, so the CAST can still meet N/A.

SELECT * FROM dbo.Products WHERE TRY_CAST(Code AS int) = 100;

Use CONCAT() instead of + to build strings

Read-only

CONCAT() converts every argument to text, so numbers join onto strings without any int conversion.

SELECT CONCAT('Order ', 100) AS Label;  -- returns 'Order 100'

Clean the data, then store numbers as numbers

Changes schema

If the column is meant to hold numbers, replace placeholders with NULL and change the column to a numeric type so the conversion never happens at query time. Check first that nothing else relies on the text values.

Caution:

Changing a column type rewrites the table on large tables and fails if indexes or constraints depend on the column. Test on a copy and run it in a maintenance window.

UPDATE dbo.Products SET Code = NULL WHERE TRY_CAST(Code AS int) IS NULL;

ALTER TABLE dbo.Products ALTER COLUMN Code INT NULL;

Examples

Implicit conversion in a WHERE comparison

CREATE TABLE dbo.Products (id INT PRIMARY KEY, Code VARCHAR(20));
INSERT INTO dbo.Products (id, Code) VALUES (1, '100'), (2, 'N/A');

-- Code is varchar; comparing it to the int 100 converts every Code to int
SELECT * FROM dbo.Products WHERE Code = 100;
Result
Msg 245, Level 16, State 1, Line 5
Conversion failed when converting the varchar value 'N/A' to data type int.

Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.

Explicit CAST of a non-numeric value

SELECT CAST('N/A' AS int) AS Result;
Result
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'N/A' to data type int.

Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.

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;
Result
Msg 245, Level 16, State 1, Line 3
Conversion failed when converting the varchar value 'Order ' to data type int.

Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.

How to prevent it

Store numbers in numeric columns and give joined columns the same type on both sides. Where text input must become a number, convert it once on the way in with TRY_CAST and reject anything that comes back NULL, rather than converting on every query.

Treat + as arithmetic and use CONCAT() for strings, and keep every branch of a CASE or UNION the same type. Related conversion failures to decimal or float raise error 8114, and values that are numeric but too large raise error 8115.

Common questions

Why did my query work for months and then start failing with error 245?

The conversion only fails when a row holds text that is not a whole number. The query worked while every value was numeric; then a row with N/A, a letter or a decimal arrived. The value in the message is that row.

Can I use ISNUMERIC to filter out bad values?

Not reliably. ISNUMERIC returns 1 for strings such as 1e5 that still cannot be converted to int (TRY_CAST('1e5' AS int) returns NULL on SQL Server 2025). Use TRY_CAST(column AS int) IS NOT NULL instead.

Why does a CASE expression raise error 245?

A CASE expression has a single result type, taken from the highest-precedence type among its branches. If one branch returns an int and another returns text, the text is converted to int and fails. Make every branch return the same type.

Learn more on CodeWithSQL

Official documentation

Last technically reviewed 23 October 2026; examples and diagnostics run on SQL Server 2025 (17.0.1145.4). Message text checked against the engine's sys.messages catalogue.

Still stuck on a SQL Server error?

Browse the full SQL Server error library, or get hands-on help from an experienced SQL professional.