Subject Re: Re: [firebird-support] case when, in, null semantics?
Author Pavel Menshchikov
Hello Kjell,

>> Kjell, could you give an example of an SQL statement (or whatever),
>> which depends on three-state logic?
KR> Sure:
KR> select *
KR> from MyTable
KR> where NullableField = 'a'
KR> select *
KR> from MyTable
KR> where NullableField <> 'a'
KR> Without three-state logic, the two selects above would, in union, return
KR> all rows. They won't, because rows with null in NullableField will not
KR> be returned by either of then.
OK, understood.
Look what I found in the FB Quick Start Guide (surprising :)
-----
• if (a = b) then
MyVariable = 'Equal';
else
MyVariable = 'Not equal';
After executing this code, MyVariable will be 'Not equal' if both a and b are NULL. The
reason is that the expression 'a = b' yields NULL if at least one of them is NULL. In an
“if...then” context, NULL behaves like FALSE. So the 'then' block is skipped, and the 'else'
block executed.
• if (a <> b) then
MyVariable = 'Not equal';
else
MyVariable = 'Equal';
Here, MyVariable will be 'Equal' if a is NULL and b isn't, or vice versa. The explanation is
analogous to that of the previous example.
-----
Thanks for the explanations, Kjell and Helen (who wrote the guide).


--
Best regards,
Pavel Menshchikov
http://www.ls-software.com