× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Richard,

Thanks for your reply. To answer your question. Yes, this is the entire procedure. I'll try setting Last_Rec to 'N', and see if that helps. I'll let you know what happens.

Mike

----- Original Message ----- From: "Richard Casey" <casey_r@xxxxxxxxxxxxxxxx>
To: "'Midrange Systems Technical Discussion'" <midrange-l@xxxxxxxxxxxx>
Sent: Monday, March 16, 2009 11:09 AM
Subject: RE: SQL Stored Procedure problem


Setting Last_Rec to 'Y' is done in the continue handler, so it only happens
when the procedure hits a NOT FOUND condition. If the FACTS table was empty,
that would occur with the initial FETCH and cause the loop to exit.
Otherwise the loop should process until it reached the end of the set of
records selected by the cursor.

Is this the entire procedure? I would recommend setting Last_Rec to 'N'
prior to the loop. If you had two sets of code like this in the same
procedure, Last_Rec would have been set to 'Y' by the first set. That would
cause the second set to exit the loop immediately.

Hope this helps!

Richard


-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of John McKee
Sent: Sunday, March 15, 2009 8:50 PM
To: Michael Soucy
Cc: Midrange Systems Technical Discussion
Subject: Re: SQL Stored Procedure problem

I have no experience with stored procedures. So, I am curious why you are
setting Last_Rec to 'Y'. I would have set it to 'N'. I do know how
Last_Rec
is to get a new value. But, starting wiyth it as 'Y' look wrong.

John McKee


Quoting Michael Soucy <michaelsoucy@xxxxxxxxxxxxxxx>:

Hello Everyone,

I'm having problem trying to write my 1st SQL Stored Procedure, and I
thought I would post my problem here, and see if someone could help. I'm
trying to read a DB2 table, and update a second table based on a value in
the
1st table. When I run the SQL stored procedure it appears to only read one
record, and then it leaves the loop. Here is my code.

CREATE PROCEDURE UPDMHGPI
LANGUAGE SQL
MODIFIES SQL DATA
BEGIN
DECLARE GPI CHAR(14);
DECLARE NEWGPI CHAR(14);
DECLARE Last_Rec CHAR(1);
DECLARE C1 CURSOR FOR SELECT FGPI, FNEWGPI FROM FACTS;
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET Last_Rec = 'Y';
OPEN C1;
FETCH_LOOP:
LOOP
FETCH C1 INTO GPI, NEWGPI;
IF Last_Rec = 'Y' THEN
LEAVE FETCH_LOOP;
END IF;
UPDATE EMRMEDS SET MDMEDGPI = NEWGPI
WHERE MDMEDGPI = GPI;
END LOOP FETCH_LOOP;
CLOSE C1;
END

I wrote this stored procedure based on an example I found in the book I have
called "SQL for eServer i5 and iSeries" by Kevin Forsythe. Can anyone tell
me
where I've gone wrong?

Sincerely,
Michael Soucy

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.