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

  1. Compare like with like (quote the literal)
  2. Use TRY_CONVERT/TRY_CAST to skip bad values
  3. Concatenate with CONCAT()

Detailed fix by platform

SQL

  1. SELECT * FROM dbo.Items WHERE TRY_CONVERT(int, Code) = 42;

How to diagnose

  1. Value — Which value fails?
  2. 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.