MSSQLMSSQL 245

MSSQL 245: Conversion Failed When Converting VARCHAR to INT

SQL Server error 245 is raised when an implicit or explicit conversion from a character type to a numeric type fails because the string contains non-numeric characters.

Example Query

SELECT * FROM products WHERE price = '19.99abc';
-- '19.99abc' cannot be converted to a numeric type

Common Causes

  1. 1Comparing a numeric column to a non-numeric string
  2. 2VARCHAR column that should be numeric containing bad data
  3. 3User input not validated before use in a query

How to Fix It

Use TRY_CAST or TRY_CONVERT which return NULL on failure instead of raising an error: TRY_CAST('abc' AS INT). Validate user input in the application. Clean up VARCHAR columns that should be numeric with ISNUMERIC() or TRY_CAST().

Need a reliable database?

Try Supabase — free PostgreSQL with a generous free tier. No credit card required.

Get started free →

Got a query causing this error?

Paste it into SQLbuddy and get an instant plain-English explanation with optimization tips.

Analyze My Query →