Sridhar
Sridhar

Reputation:

Character set mismatch

I have a SQL statement like this:

SELECT 
  a.ColumnA, b.ColumnB || 
 CASE WHEN TRIM(c.ColumnC) IS NOT NULL THEN ' (' || c.ColumnC || ')' ELSE '' END AS ClassName
 FROM TableA a INNER JOIN TableB b ON a.SomeColumn = b.SomeColumn 
 INNER JOIN TableC c on a.SomeCol = c.SomeCol

I'm getting an error "Character set mismatch" at the " ELSE '' " part of the CASE expression. Can someone suggest where I'm doing it wrong? Thank you.

Upvotes: 3

Views: 7944

Answers (4)

Roger
Roger

Reputation: 2952

Just erase the ELSE, would make your code easier to read

Upvotes: 0

Matt Birchall
Matt Birchall

Reputation: 11

CASE WHEN TRIM(c.ColumnC) IS NOT NULL 
     THEN ' (' || c.ColumnC || ')' 
     ELSE N'' END A

is a more concise solution. N'' gives you a unicode empty string

Upvotes: 1

anon
anon

Reputation:

You cannot concatenate VARCHAR and NVARCHAR values without a CAST statement.

Upvotes: 2

jva
jva

Reputation: 2807

Did you try replacing '' with NULL? Also, try removing ELSE part altogether because it will return NULL anyway.

Upvotes: 0

Related Questions