title: Can't run exec command in MYSQL stored procedure
body: <pre><code>DELIMITER $$
  
  USE `RTList`$$
  
  DROP PROCEDURE IF EXISTS `INSERT_INTO_MT_Tables`$$
  
  CREATE DEFINER=`root`@`localhost` PROCEDURE `INSERT_INTO_MT_Tables`(
  IN mtTableName VARCHAR(10)
  , IN mTableName VARCHAR(15)
  , IN mtField VARCHAR(15)
  , IN mtItemID VARCHAR(15)
  , IN mtItemName VARCHAR(15)
  , IN AdminID INT)
  BEGIN
  
  DECLARE @SQLString VARCHAR(200);
  
  SET @SQLString = 
  'INSERT INTO ' + mtTableName +
  '(' + mtItemID + ', ' + mtField + ', User_Created, Date_Created, User_Modified, Date_Modified)'
  + ' SELECT ' + mtItemID + ' , ' + mtField + ', AdminID, NOW(), AdminID, NOW()
  FROM ' + mTableName + '
  WHERE ' + mtField + ' = ''' + mtItemName + ''' LIMIT 1;';
  
  PREPARE test FROM @SQLString;
  EXECUTE test;
  
  END$$
  
  DELIMITER ;
  
  CALL INSERT_INTO_MT_Tables('MT_Phone', 'M_Phone', 'Phone_Number', 'PhoneID', '12345678', 1);
  </code></pre>
  
  <p>Here is the error message after I changed (execute cmd after end):</p>
  
  <pre><code>Error Code: 1064
  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'EXECUTE test;
  DELIMITER' at line 2
  </code></pre>
  
  <p>Here is the error message after I changed (execute cmd before end):</p>
  
  <pre><code>Error Code: 1064
  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@SQLString VARCHAR(200);
  SET @SQLString = 
  'INSERT INTO ' + mtTableName +
  '(' + ' at line 9
  </code></pre>
  
  <p>Hi there,</p>
  
  <p>Please see above coding of mine. I have little knowledge for stored procedure.
  But I tried to look around before posted this question.
  Seems the cmd is simple, but still with no luck i can run this cmd.</p>
  
  <p>Could you please tell me where I wrote it wrongly so that this didn't work?</p>
  
  <p>really appreciate your knowledge with this basic question.</p>
  
  <p>thanks.</p>