CASE SQL Origin: Data OSI layer 7 · Application Last updated 18 Nov 2026

CASE expression returns mixed types: conversion failed / types cannot be matched

The branches of a CASE expression produce incompatible data types (text and number, date and string).

Exact message you may see CASE types cannot be matchedCASE types integer and text cannot be matchedConversion failed when converting the varchar value to data type int CASECASE expression mixed data typesORA-00932 inconsistent datatypes CASE
Seen on: SQL PostgreSQL SQL Server Oracle

Meaning

All THEN/ELSE results must resolve to a common type. Cast branches explicitly (CAST(x AS varchar)), and watch for NULL/empty strings mixed with numbers.

Common causes

  • Number and text mixed in the branches
  • Date and string branches
  • Implicit conversion order (data type precedence)
  • Empty string in a numeric branch
  • NULL typed unexpectedly

⚡ Quick fix

  1. Cast every branch to the same type
  2. Use NULL or 0 consistently
  3. Check data type precedence rules for your DB

Detailed fix by platform

SQL

  1. SELECT CASE WHEN qty > 0 THEN CAST(qty AS varchar(10)) ELSE 'none' END FROM stock;

How to diagnose

  1. Branch types — Same?
  2. Cast — Explicit?
  3. Empty string — In numeric branch?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

= NULL — WHERE col = NULL returns no rows (use IS NULL) (SQL)= NULL100038 — Snowflake: Numeric value 'X' is not recognized (SQL)100038242 — SQL Server Msg 242: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value (SQL)242245 — SQL Server: Conversion failed when converting the varchar value 'x' to data type int. (Msg 245) (SQL)24542804 — ERROR: column "x" is of type integer but expression is of type text — HINT: You will need to rewrite or cast the expression. (PostgreSQL)428048114 — SQL Server Msg 8114: Error converting data type varchar to numeric (SQL)8114Array to string conversion — Warning: Array to string conversion (PHP)Array to string conve…AttributeError — AttributeError: 'X' object has no attribute 'y' (Python)AttributeErrorCASE

Explore the map of this error Full error map →

🧠 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.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.