Link to home
Start Free TrialLog in
Avatar of Nemetona
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.
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Just re-read the question and see you are trying to change the variable name you are passing to.
May be able to do this with dynamic code, but will post back with some thoughts on a different way.
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
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 Nemetona
Nemetona

ASKER

Thank you, that works for me.