Subject | Re: [firebird-support] Optional parameter in a select statement |
---|---|
Author | Ivan Prenosil |
Post date | 2005-08-25T10:25:28Z |
> I'm trying to do a select where I can get the log records from aIt is because this part of where clause
> specific User, or records of all user if '-1' is passed in the parameter.
>
> I'm using the following select statement:
> select * from LogTable
> where ( (:User = cast('-1' as char(15))) or (User = :User))
>
> It works but the plan I'm receiving from IBExperts is always NATURAL,
( (:User = cast('-1' as char(15)))
can't use index anyway, so using it for
(User = :User))
would just make things worse.
> how can I write the same code IN ONE STATEMENT (without an IF) and useselect * from LogTable
> the correct index?
where (User = :User)
UNION ALL
select FIRST ( CASE WHEN :User='-1' THEN 1000000000 ELSE 0 END ) * from LogTable
Ivan
http://www.volny.cz/iprenosil/interbase/