Subject Looping a Stored Procedure
Author Muthu
Hi,

I have a Stored Procedure, which takes startdate and endate as input parameters and executes fine and returns values.

I have written another SP that use the existin SP in a loop and get results for given number of days. But it is just returning one row.

Here is my SP.

*********************************

CREATE OR ALTER PROCEDURE ZOUT_LIST(
STARTDATE TIMESTAMP,
ENDDATE TIMESTAMP)
RETURNS (
REPORTSTARTDATE DATE,
REPORTENDDATE DATE,
STARTRECEIPT INTEGER,
ENDRECEIPT INTEGER,
RECEIPTCOUNT INTEGER,
TAXABLESALES DECIMAL2,
NONTAXABLESALES DECIMAL2,
TAX DECIMAL2,
SALESRETURN DECIMAL2,
SALESRETURNCOUNT INTEGER,
DISCOUNT DECIMAL2,
TENDERTYPE SMALLINT,
PAYMENTNAME VARCHAR(20),
PAYMENTAMOUNT DECIMAL2,
PAYMENTCOUNT INTEGER)
AS
BEGIN
REPORTSTARTDATE = STARTDATE;
REPORTENDDATE = STARTDATE + 1;
FOR SELECT STARTRECEIPT,ENDRECEIPT,RECEIPTCOUNT,TAXABLESALES,
NONTAXABLESALES,TAX,SALESRETURN,SALESRETURNCOUNT,DISCOUNT,TENDERTYPE,
PAYMENTNAME,PAYMENTAMOUNT,PAYMENTCOUNT
FROM ZOUTPERIOD(:REPORTSTARTDATE,:REPORTENDDATE)
WHERE :REPORTSTARTDATE <= :ENDDATE
INTO :STARTRECEIPT,:ENDRECEIPT,:RECEIPTCOUNT,:TAXABLESALES,
:NONTAXABLESALES,:TAX,:SALESRETURN,:SALESRETURNCOUNT,:DISCOUNT,:TENDERTYPE,
:PAYMENTNAME,:PAYMENTAMOUNT,:PAYMENTCOUNT
DO
BEGIN
REPORTSTARTDATE = REPORTSTARTDATE + 1;
REPORTENDDATE = REPORTSTARTDATE + 1;
SUSPEND;
END
END
*************************************

Thanks for your help
Muthu Annamalai