Subject RE: [firebird-support] How to use case and where together
Author Leyne, Sean
Guido,

> I want to run the following query
>
> select acdate,accompleted,
> case
> when ((acdate<current_date) and (accompleted=0)) then 1
> else 0
> end as acoverdue_new
> from activities
> where acoverdue_new<>0
>
> and get the error that the column acoverdue is unknown.

You are trying to use a column 'alias' (acoverdue) in a where clause.

This is not yet supported -- it has been requested, though.


> Is it possible to use the result of a case statement in the where
clause
> and if yes, how can I do it?

Very simple.

select
acdate,
accompleted,
case
when ((acdate<current_date) and (accompleted=0)) then 1
else 0
end as acoverdue_new
from activities
where
(case
when ((acdate<current_date) and (accompleted=0)) then 1
else 0
end) <> 0


Sean