Subject Re: [firebird-support] Re: Optional parameter in a select statement
Author Ivan Prenosil
> > select * from LogTable
> > where (User = :User)
> > UNION ALL
> > select FIRST ( CASE WHEN :User='-1' THEN 1000000000 ELSE 0 END ) *
> from LogTable
>
> Thanks a lot by the help, but unfortunately it doesn't solve my
> problem... If the select had a single parameter it was ok, but there
> are many others and I would have lots of UNION...

Why can't you use it ? Is the command too long ? Or you want to use
your original command unchanged ? Or ... ?

Here is another method:

SELECT *
FROM LogTable
WHERE Usr STARTING :User AND (:User IN (Usr,''))

(you have to use empty string '' to indicate the need to fetch all rows)


>
> I used to do the way I wrote above in Sybase and the indices where
> found without problem... That's the reason of my question.
>
> Well, I'm going to dynamically write the where clause...
>
> Does anybody knows if the FB has anything like:
>
> declare variable command varchar(1000);
> select 'select * from TABLE' from RDB$DATABASE into :command;
> execute(command);

Are you going to use it inside stored procedure ?

Ivan
http://www.volny.cz/iprenosil/interbase/