Where I have more than one table in my database for use with (similar, but) different products.
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).
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 ;
It is possible to create a command like this:
As you can see, you can push any string/variable you want into that command (using variables wherever you’d like.