Subject | Re: [firebird-support] Fw: An empty string in a CASE expression will result in a space |
---|---|
Author | Ivan Prenosil |
Post date | 2004-02-13T19:30:11Z |
> It seems that an empty string used in a CASE expression is converted to aBoth string literals '' and 'x' are of type CHAR, not VARCHAR,
> 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'
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/