Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

loops and cursors

yaaraeryaaraer Member Posts: 1
i am trying to run this on mysql and get an error because of the select inside the second loop. any thoughts? (this is only 2 levels but the final will have 4)
[code]
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE a,b,c,d CHAR(16);
DECLARE cur1 CURSOR FOR select status, bookingheader.agencyid from bookingitems left join bookingheader on (bookingitems.bookingnumber = bookingheader.bookingnumber) left join agencylinks on (bookingheader.agencyid = agencylinks.agencyid) where agencylinks.parentid = nID;
DECLARE cur2 CURSOR FOR select status, bookingheader.agencyid from bookingitems left join bookingheader on (bookingitems.bookingnumber = bookingheader.bookingnumber) left join agencylinks on (bookingheader.agencyid = agencylinks.agencyid) where agencylinks.parentid = b;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
OPEN cur1;
REPEAT
FETCH cur1 INTO a, b;
IF NOT done THEN
select a,b;
OPEN cur2;
REPEAT
FETCH cur2 INTO c,d;
IF NOT done THEN
select c,d;
END IF;
UNTIL done END REPEAT;
CLOSE cur2;
END IF;
UNTIL done END REPEAT;
CLOSE cur1;
END
[/code]
Sign In or Register to comment.