SQL Server: Conversion failed when converting the varchar value 'x' to data type int. (Msg 245)
SQL Server tried to convert text to a number (often implicitly) and hit a non-numeric value.
Seen on:
SQL
Meaning
Comparing a varchar column with an int forces conversion of every row; one non-numeric value breaks the query. Data type precedence makes int win.
Common causes
- Comparing varchar columns with numbers
- Mixed data in a varchar column
- String concatenation with + and numbers
⚡ Quick fix
- Compare like with like (quote the literal)
- Use TRY_CONVERT/TRY_CAST to skip bad values
- Concatenate with CONCAT()
Detailed fix by platform
SQL
SELECT * FROM dbo.Items WHERE TRY_CONVERT(int, Code) = 42;
How to diagnose
- Value — Which value fails?
- Expression — Implicit conversion where?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026