Subject | Re: [ib-support] cursors in sp?? |
---|---|
Author | Lucas Franzen |
Post date | 2002-10-03T10:28:33Z |
Regina,
Regina Phandu schrieb:
Since there is a SUSPEND in the procedure it should work for <n>
records.
SELECT SUM ( QTY ) FROM TRANSAKTION
WHERE PROD_CODE = :PROD_CODE INTO :SUMQTY;
IF ( SUMQTY IS NULL ) THEN SUMQTY = 0;
QTY = PRODQTY - SUMQTY;
/* =============== */
/* UPDATE / DELETE */
/* =============== */
IF ( SUMQTY > 0 ) THEN
BEGIN
UPDATE PRODUCT SET
PROD_QTY = :SUMQTY
WHERE PROD_CODE = :PROD_CODE;
DELETE FROM TRANSACTION WHERE PROD_CODE = :PROD_CODE;
END
SUSPEND;
Since you want to do an update it might be a better idea just to sum the
transaction table, update the appropriate entries in product and select
* from product (since irt has the new sum in the field QTY then).
You can do the summing on transaction like:
FOR SELECT SUM ( QTY ), PROD_CODE from TRANSACTION
GROUP BY PROD_CODE
...
then.
Luc.
Regina Phandu schrieb:
>How do you get the results?
> Lucas,
>
> the sp that you gave me works well, but it only works for 1 record. what i
> need is a cursors, i believe.
Since there is a SUSPEND in the procedure it should work for <n>
records.
> and i also need to update the quantity of the product. not only returnsYou can do this within the procedure, too.
> values/display the values.
SELECT SUM ( QTY ) FROM TRANSAKTION
WHERE PROD_CODE = :PROD_CODE INTO :SUMQTY;
IF ( SUMQTY IS NULL ) THEN SUMQTY = 0;
QTY = PRODQTY - SUMQTY;
/* =============== */
/* UPDATE / DELETE */
/* =============== */
IF ( SUMQTY > 0 ) THEN
BEGIN
UPDATE PRODUCT SET
PROD_QTY = :SUMQTY
WHERE PROD_CODE = :PROD_CODE;
DELETE FROM TRANSACTION WHERE PROD_CODE = :PROD_CODE;
END
SUSPEND;
Since you want to do an update it might be a better idea just to sum the
transaction table, update the appropriate entries in product and select
* from product (since irt has the new sum in the field QTY then).
You can do the summing on transaction like:
FOR SELECT SUM ( QTY ), PROD_CODE from TRANSACTION
GROUP BY PROD_CODE
...
then.
> so, i guess, i need cursors and updating theSee Helen's answer.
> product qty itself.
> I tried so hard with cursors, but i still can't make it work.
Luc.