Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

"While loop" loops extra times

This is a related question that Davelash helped me with.
The select statement returns 3 rows. I need the 3 rows to concat. But the while loop loops 5 times and the ***last row*** is concated twice more. So, it does 5 loops but it should do 3.

So, when I look at "textNote"...the last row is repeated more than once.
DECLARE textNote VARCHAR(4000) ;
 DECLARE chunk VARCHAR(60);
 Declare  DName  VARCHAR(30); 
 
DECLARE EOF_COND INTEGER Default 0;
DECLARE NOT_FOUND CONDITION FOR SQLSTATE '02000';
 
 
 DECLARE c1 CURSOR WITH RETURN  For 
 
  SELECT .....
 
DECLARE CONTINUE HANDLER FOR NOT_FOUND
set EOF_COND = -300;
 
      Open c1;
 
    SET textNote = ' ';
    while (EOF_COND =0 ) do
         fetch c1 into DName, chunk;
        SET textNote = textNote || ' ' || chunk ;
       insert into testing2 values (textNote);  --for testing
    END While;
    
      Set DebtorName=DName;
   Set textValue = textNote;
 Close c1;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Member_2_2484401
Member_2_2484401
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Camillia

ASKER

let me try
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i havent tried it . Will do it this morning.
thanks , it worked. Finally.

I will close this and open another question. I really need to get the results back in a resultset. Right now, I get it using "out" parameters. but will open another question.

Thanks again. Kamila.