title: Returning Error in a Dynamic MySql Procedure
body: <p>I am developing some functions/procedures for a much larger system, that is gona be used in others tables, so i tried to create a Dynamic MySql Procedure, to pass the name of the tables by variables,and get an &quot;InOut&quot; variable to return the result that i want, but it is returning me some Syntax error, i don't know where i am geting wrong in the code, so if someone knows a way better to do it, or get where the error is, i will be very thankfull!</p>
  <p>Here is The Error that is returning:</p>
  <p>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 'If Exists (Select cliente26 From da26s9                           Where da26s9.c' at line 1.</p>
  <p>Here is how i am Calling the Procedure:</p>
  <pre><code>Call FilTabMes('da26s9','codigo26','cliente26','002715',@string);
  </code></pre>
  <p>Here is The Procedure that i am struggling with:</p>
  <pre><code>CREATE PROCEDURE `FilTabMes`(vTabMes_ Char(32),vCodMes_ Char(32),vCodTab_ Char(32),vComFin_ Integer,InOut vResPes_ Char(32))
  Begin 
     Declare vSelTab VarChar(1000);
     Set @vSelTab = CONCAT('Select ',vCodTab_,' From ',vTabMes_,'
                            Where ',vTabMes_,'.',vCodMes_,&quot; Like &quot;,vComFin_);
     Set @vSelTab = CONCAT('If Exists(',@vSelTab,')
                               Begin
                                  Set vResPes_ = &quot;T&quot;;
                               End
                            Else
                               Begin
                                  Set vResPes_ = &quot;F&quot;;
                               End
                            End If');
     Prepare stmt1 From @vSelTab;
     Execute stmt1;   
  End
  
  </code></pre>