title: MySql Stored Procedure Select Table
body: <p>Where I have more than one table in my database for use with (similar, but) different products.</p>
  
  <p>Is it possible to select a table to work with based on a parameter (example below)? 
  (This would save me having multiple similar copies of the same procedure).</p>
  
  <hr>
  
  <pre><code>DELIMITER $$
  
  DROP PROCEDURE IF EXISTS `dostuff` $$
  CREATE PROCEDURE `dostuff`(IN prod_code VARCHAR(10))
  BEGIN
  
  IF INSTR(prod_code, 'product_a') THEN
      myTable = product_a_table
  ELSE IF INSTR(prod_code, 'product_b') THEN
      myTable = product_b_table
  END IF
  
  -- do stuff on myTable such as SELECT and UPDATE
  
  END $$
  
  DELIMITER ;
  </code></pre>