Subject Re: [firebird-support] strange problem with extract(month from "date")
Author Helen Borrie
At 11:51 PM 27/01/2004 -0200, you wrote:
>Hi there,
>
>I am using FB 1.5 SS RC8 on WinXP home edition
>
>I have a problem...
>
>When I do some left joins between tables and try to use extract(month from
>date_field) and the field contains null I get the following message.
>
>Statement failed, SQLCODE = -833
>
>expression evaluation not supported
>
>the problematic queries are...

[..snip... a series of queries with left joins that cause nulls to be
returned to the date fields...]

EXTRACT() can't do anything with NULL ("expression evaluation not
supported") so don't write queries that pass NULLs to EXTRACT().

What is the problem you want to solve? Do you want to find a way to
prevent EXTRACT() being called if there is a null there? If so, try using
CASE().

select
t1.id, t1.foo,
t2.id, t2.test_month,
t3.id, t3.test_date,
(CASE
t3.test_date WHEN NULL THEN NULL
ELSE Extract(Month from t3.test_date)
END) AS M,
(CASE
t3.test_date WHEN NULL THEN NULL
ELSE Extract(Year from t3.test_date)
END) AS Y

/heLen