Dynamic table name at sql statement

The usage of dynamic table names within the query is best with Prepared Staments,
also in mysql for concatenation the function is concat

SET @id := '47';
SET @table := concat(@id,'_2013_2014_voucher');
set @qry1:= concat('select * from ',@table);
prepare stmt from @qry1 ;
execute stmt ;

You can do it for the delete query as well

Leave a Comment