Subject Re: [firebird-support] multiple selects for a nested query
Author Helen Borrie
At 11:18 AM 7/03/2005 +0000, you wrote:


>Hello
>
>I am attempting to write a stored procedure that will return me
>multiple rows. I need to run 2 seperate selects and then process these
>results in 3rd (nested?) query.
>My pseudo code statment looks something as follows:
>
>for select <specs>
>into <vars>
>select <spec>
>into <vars>
>do
> begin
> <nested statements>
> end
>
>The question that I have is concerned with the 2nd select. Is this a
>nested loop itself and should it be wrapped in a begin and end ? I
>expect that the select query will return multiple rows for the 2nd
>query to use before passing on to the 3rd.

Sure. <nested statements> can themselves be (or include) FOR SELECT
loops. Take the utmost care to initialise the INTO and RETURNING_VALUES
variables on each turn of the loop. They are "just variables" = they don't
get re-initialised by any wandering mage as each loop loops. If you don't,
you'll come unstuck if some inner SELECT doesn't return any rows...

./hb