Subject Re: Building query strings in stored procedures?
Author willogibbo
--- In firebird-support@yahoogroups.com, Tim Gahnström
<tim.gahnstrom@i...> wrote:

> > Check the EXECUTE STATEMENT statement. You can build up a
> > SQL statement in a procedure then execute it.
>
> You could pass arrays to a stored procedure (I don't know how) and
build the query string inside your SP and use the EXECUTE STATEMENT as
Ann suggested. It will give you the flexibility you are looking for
but not any speed increase.
>
> The reason SPs are faster is because they are compiled and optimized
in advance and this is not possible using the EXECUTE STATEMENT.
>
> This is a drawback but it also means that you can just as well build
your query string on the clientside (in php) and pass it as a string
to the SP. This way you don't have to pass in and parse an array annd
you can keep most of the logic in PHP.
>
> If you really need the speed your option is to skip the EXECUTE
STATEMENT and only use ordinary IF statements etc in your SP.
>
> Tim


Thanks Tim and Ann for your thoughts.

I don't quite understand how to make EXECUTE work for me. Perhaps you
could mention some kind of basic example to get me going.

I know this is wrong, but the sort of thing I have tried so far, using
a basic FOR SELECT ... DO loop has been

FOR SELECT assetid FROM tblasset querystring
INTO :outputfield
DO
BEGIN
SUSPEND;
END

in which querystring would be an input variable with something like
'WHERE groupid=162'

This doesn't work and shows that I'm not with it on this!

Thanks again for your input. Will