Subject | Re: [firebird-support] IIF bug? |
---|---|
Author | Mr. John |
Post date | 2013-01-23T13:20:38Z |
Thanks for your answer !
________________________________
From: Mark Rotteveel <mark@...>
To: firebird-support@yahoogroups.com
Sent: Wednesday, January 23, 2013 3:14 PM
Subject: Re: [firebird-support] IIF bug?
On Wed, 23 Jan 2013 04:49:17 -0800 (PST), "Mr. John" mr_johnmr@...>
wrote:
argument). String literals in Firebird are CHAR (and not VARCHAR). The CHAR
datatype is always padded with spaces upto its declared length, so '' is
also CHAR(14) and actually returned as ' ' (14 spaces). For
the behavior that you want, you need to use
TRIM(IIF(1>2,'00000000000000','')), or TRIM(IIF(1>2,CAST('00000000000000'
AS VARCHAR(20)),'')) to force IIF to have a returntype of VARCHAR.
Mark
[Non-text portions of this message have been removed]
________________________________
From: Mark Rotteveel <mark@...>
To: firebird-support@yahoogroups.com
Sent: Wednesday, January 23, 2013 3:14 PM
Subject: Re: [firebird-support] IIF bug?
On Wed, 23 Jan 2013 04:49:17 -0800 (PST), "Mr. John" mr_johnmr@...>
wrote:
> Hi !string
> I'm using FB 2.5.2 on XP
> I've discovered a strange behavior for IIF function:
>
> SELECT '11'||(IIF(1>2,'00000000000000',''))||'.22' FROM rdb$database
>
>
> as it can see condition is always false,IIF should result an empty
> but the result is notThe return type of IIF in this case is CHAR(14) (the length of the longest
> 11.22
> ,the result is 11 .22
> why?
argument). String literals in Firebird are CHAR (and not VARCHAR). The CHAR
datatype is always padded with spaces upto its declared length, so '' is
also CHAR(14) and actually returned as ' ' (14 spaces). For
the behavior that you want, you need to use
TRIM(IIF(1>2,'00000000000000','')), or TRIM(IIF(1>2,CAST('00000000000000'
AS VARCHAR(20)),'')) to force IIF to have a returntype of VARCHAR.
Mark
[Non-text portions of this message have been removed]