tags:

views:

354

answers:

2

Hi All, 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.

A: 

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

jva
The intention is to append the value from ColumnC, if exists, to ColumnB. If I replace the ELSE part with NULL, then the entire value will become NULL (b.ColumnB || NULL = NULL) and I don't want that.
Not true.select 'a'||null from dual;returns 'a'
jva
Also, empty string constant ('') is just a way to write "to_char(NULL)".
jva
+1  A: 

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

Adam Hawkes