Subject Re: [firebird-support] Fw: An empty string in a CASE expression will result in a space
Author Ivan Prenosil
> It seems that an empty string used in a CASE expression is converted to a
> space:
>
> SELECT 'aa' || CASE WHEN (1 = 1) THEN '' ELSE 'x' END || 'bb'
> FROM rdb$database
>
> This will result in 'aa bb' with a space between aa and bb. I expect 'aabb'

Both string literals '' and 'x' are of type CHAR, not VARCHAR,
and so the result is converted to CHAR with the length of the longer one, i.e. CHAR(1).

This
SELECT 'aa' || CASE WHEN (1 = 1) THEN '' ELSE 'xyz' END || 'bb'
should result in
' '


In these examples CASE will be of VARCHAR type
SELECT 'aa' || CASE WHEN (1 = 1) THEN CAST('' AS VARCHAR(1)) ELSE 'x' END || 'bb'
SELECT 'aa' || CASE WHEN (1 = 1) THEN '' ELSE CAST('x' AS VARCHAR(1)) END || 'bb'
and so the result will be empty string.

Ivan
http://www.volny.cz/iprenosil/interbase/