Nemetona
asked on
within an MySQL stored procedure how can I dynamically set the variable name?
i want to iterate through the records in a table and place the values into variables within a stored procedure.
DECLARE movetonext_tcl1 INT;
DECLARE movetonext_tcl2 INT;
DECLARE movetonext_tcl3 INT;
DECLARE movetonext_tcl4 INT;
DECLARE calculate_tcl1 INT;
DECLARE calculate_tcl2 INT;
DECLARE calculate_tcl3 INT;
DECLARE calculate_tcl4 INT;
declare x int;
SET x = 1;
WHILE x <= 4 DO
select movenextvalue FROM `tcl rules` where id=x into movetonext_tcl1;
select calculatevalue FROM `tcl rules` where id=x into calculate_tcl1;
SET x = x + 1;
END WHILE;
I need to know if it is possible to dynamically change the movetonext_tcl1 to tcl2,3 and 4 as I look through the statement.
DECLARE movetonext_tcl1 INT;
DECLARE movetonext_tcl2 INT;
DECLARE movetonext_tcl3 INT;
DECLARE movetonext_tcl4 INT;
DECLARE calculate_tcl1 INT;
DECLARE calculate_tcl2 INT;
DECLARE calculate_tcl3 INT;
DECLARE calculate_tcl4 INT;
declare x int;
SET x = 1;
WHILE x <= 4 DO
select movenextvalue FROM `tcl rules` where id=x into movetonext_tcl1;
select calculatevalue FROM `tcl rules` where id=x into calculate_tcl1;
SET x = x + 1;
END WHILE;
I need to know if it is possible to dynamically change the movetonext_tcl1 to tcl2,3 and 4 as I look through the statement.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, that works for me.
May be able to do this with dynamic code, but will post back with some thoughts on a different way.