Reputation:
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
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
Reputation:
You cannot concatenate VARCHAR and NVARCHAR values without a CAST statement.
Upvotes: 2
Reputation: 2807
Did you try replacing '' with NULL? Also, try removing ELSE part altogether because it will return NULL anyway.
Upvotes: 0