Subject Case statements in where clause
Author Nigel Weeks
Does anyone know of/have any examples of using case statements in the where
clauses of Select queries?
I'm wanting to run different types of selects depending on nulls, and i'd
rather on doing if blocks and multiple queries, as there'd be 2^n
combinations of searches...
If a parameter is not null, then it is used in the search, otherwise, any
value of the field is returned...possible?

select int_id, str_name, str_address
from table
where
(case when int_id id is not null then
int_id = :int_id /* Apply the provided filter */
else
1 /* I think this makes the condition true, and lets the record
match... */
)
and
(case when str_name is not null then
str_name = :str_name
else
1
)
...

What version of Firebird were they introduced in?


--------------------------------------------------------
Nigel Weeks
E-Easy
15 Wellington St. Launceston Tas 7250
Ph. 61 3 6334 6664
Fax. 61 3 6331 7032
Email. nigel@...
Web: www.e-easy.com.au
--------------------------------------------------------