Subject Re: [firebird-support] Looping a Stored Procedure - Email found in subject
Author Michael Ludwig
Leyne, Sean schrieb am 26.05.2010 um 17:41:17 (-0400):

> > FOR SELECT STARTRECEIPT,ENDRECEIPT, [...]
> > FROM ZOUTPERIOD(:REPORTSTARTDATE,:REPORTENDDATE)
> > WHERE :REPORTSTARTDATE <= :ENDDATE
> > INTO :STARTRECEIPT,:ENDRECEIPT, [...]
> > DO
> > BEGIN
> > REPORTSTARTDATE = REPORTSTARTDATE + 1;
> > REPORTENDDATE = REPORTSTARTDATE + 1;
> > SUSPEND;
> > END
> > END
>
> You don't have the ZOUTPERIOD in a loop. The ZOUTPERIOD SP will only
> be called once, with the initial parameter values.

Might also be what the OP wants, as ZOUTPERIOD may return multiple rows
and thus feed the loop. But you've probably guessed right ...

> You need to use the following approach:
>
> ...
> WHILE (ReportEndDate <= EndDate) DO
> BEGIN
> FOR SELECT ....
> INTO ....
> DO
> BEGIN
> SUSPEND;
> REPORTSTARTDATE = REPORTSTARTDATE + 1;
> REPORTENDDATE = REPORTSTARTDATE + 1;
> END
> END
> ...
>
>
> Sean

--
Michael Ludwig