Character set mismatch

I have an 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 get the "Character set mismatch" error message in the CASE element "ELSE". Can anyone suggest where I am doing this wrong? Thanks.

+3
source share
4 answers

You cannot combine VARCHAR and NVARCHAR values ​​without a CAST statement.

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

is a shorter solution. N '' gives an empty string in unicode

+1
source

Have you tried replacing '' with NULL? Also, try removing the ELSE part completely, because it will return NULL anyway.

0
source

Just uninstall ELSE, make code easier to read

0
source

Source: https://habr.com/ru/post/1712298/


All Articles