title: Issue with complex mysql query using prepared statement
body: <p>The following procedure does not execute. <code>int_id</code> is a user-defined input</p>
  
  <p>My goal is to use <code>STR_TABLE_NAME</code> as a dynamic variable for a table. 
  <em>NB: the query works however, if i replace it by the name of my target table and remove "SET @prep_stmt =".</em></p>
  
  <pre><code>BEGIN
  
  DECLARE STR_TABLE_NAME VARCHAR(100) DEFAULT NULL;
  SELECT `table_source` INTO STR_TABLE_NAME FROM `list_repository` WHERE 
  id=`int_id` LIMIT 1;
  
  DROP TABLE IF EXISTS `loyaltytry`;
  SET @prep_stmt = CREATE TABLE `loyaltytry` as (SELECT Months as month, 
  Number_of_New_Customers as `new_customers` , `Number_of_Repeat_Customers`  
  as `repeat_customers`
  from
  (SELECT  monthname(Months) as Months, month(Months)  as `Month_number`,
  sum(CASE WHEN REP_COUNT ='no' then cnts end) as `Number_of_New_Customers`,
  sum(CASE WHEN REP_COUNT = 'yes' then cnts end) as 
  `Number_of_Repeat_Customers`
  from (
  SELECT months,REP_COUNT,count(*) as cnts
  from (
      SELECT (date_commande_client) as Months , numero,
      CASE WHEN cnt &gt; 1 THEN 'yes'
      ELSE 'no'
      END AS REP_COUNT
      from ( 
      SELECT COUNT(*) as cnt, date_commande_client, numero
      FROM  STR_TABLE_NAME           
          WHERE YEAR(date_commande_client)=2017
          AND intitule IN (SELECT showroom_name FROM `showrooms` WHERE 
  id_region=`int_id`)
         group by date_commande_client , numero) as tmp) as final
      GROUP BY Months,REP_COUNT ) as tmp1
  GROUP BY monthname(Months),month(Months)
  ORDER BY Month_number) as finalll
  );
  
  PREPARE stmt FROM @prep_stmt; 
  EXECUTE stmt; 
  DEALLOCATE PREPARE stmt;
  
  END
  </code></pre>