Subject Re: [ib-support] cursors in sp??
Author Lucas Franzen
Regina,

you can write a stored procedure like:

SET TERM #;
CREATE PROCEDURE SEL_PRODUCTQTY
RETURNS (
PROD_CODE INTEGER,
QTY INTEGER
)
AS
declare variable PRODQTY INTEGER;
declare variable SUMQTY INTEGER;
BEGIN
FOR SELECT PROD_CODE, QTY FROM PRODUKT
INTO :PROD_CODE, :PRODQTY
DO BEGIN
SELECT SUM ( QTY ) FROM TRANSAKTION
WHERE PROD_CODE = :PROD_CODE INTO :SUMQTY;

IF ( SUMQTY IS NULL ) THEN SUMQTY = 0;

QTY = PRODQTY - SUMQTY;
SUSPEND;
END
END#
SET TERM ;#

Then you can select the result with a Query by:

SELECT * FROM SEL_PRODUCTQTY;



Hth

Luc.