Subject | Help with Stored Procedure |
---|---|
Author | Bert_Herngreen |
Post date | 2007-01-18T20:01:01Z |
Hello,
Can somebody give me some advice?
I want to use a stored procedure to update a field 'VOLGNUMMER_CRECO'
by a counter (i) and a Sort statement:
CREATE PROCEDURE SORTEER_BANKAFSCHRIFT (
BATCH_ID integer)
AS
DECLARE VARIABLE i integer;
DECLARE VARIABLE BA_VOLGNUMMER integer;
BEGIN
i = 0;
FOR SELECT BA.VOLGNUMMER FROM BANKAFSCHRIFT BA
WHERE BA.BATCH_ID = :BATCH_ID
ORDER BY BA.BATCH_ID,BA.CD_INDICATOR DESC, BA.ABSBEDRAG
FOR UPDATE
INTO :BA_VOLGNUMMER
DO
BEGIN
i = i + 1;
UPDATE BANKAFSCHRIFT B2 SET VOLGNUMMER_CRECO = :i
WHERE (B2.BATCH_ID = :BATCH_ID AND B2.VOLGNUMMER= :BA_VOLGNUMMER);
SUSPEND;
END
END
Monitoring it in a stored procedure debugger, I see each record of
the table is beeing processed, and i is incremented each time, but
after the commit, only the first record has been updated, the rest of
the records still has 'null' for the 'VOLGNUMMER_CRECO' field?
Kind regards,
Bert
Can somebody give me some advice?
I want to use a stored procedure to update a field 'VOLGNUMMER_CRECO'
by a counter (i) and a Sort statement:
CREATE PROCEDURE SORTEER_BANKAFSCHRIFT (
BATCH_ID integer)
AS
DECLARE VARIABLE i integer;
DECLARE VARIABLE BA_VOLGNUMMER integer;
BEGIN
i = 0;
FOR SELECT BA.VOLGNUMMER FROM BANKAFSCHRIFT BA
WHERE BA.BATCH_ID = :BATCH_ID
ORDER BY BA.BATCH_ID,BA.CD_INDICATOR DESC, BA.ABSBEDRAG
FOR UPDATE
INTO :BA_VOLGNUMMER
DO
BEGIN
i = i + 1;
UPDATE BANKAFSCHRIFT B2 SET VOLGNUMMER_CRECO = :i
WHERE (B2.BATCH_ID = :BATCH_ID AND B2.VOLGNUMMER= :BA_VOLGNUMMER);
SUSPEND;
END
END
Monitoring it in a stored procedure debugger, I see each record of
the table is beeing processed, and i is incremented each time, but
after the commit, only the first record has been updated, the rest of
the records still has 'null' for the 'VOLGNUMMER_CRECO' field?
Kind regards,
Bert