title: Mysql "IF" in query
body: <p>I have few tables</p>
  
  <pre><code>table201202
  table201203
  table201204
  table201205  
  ...
  tableversion
  </code></pre>
  
  <p>In <code>tableversion</code> I have columns:
  Version_ID  Admin_ID    MONTH   YEAR</p>
  
  <p>I need to get something like this</p>
  
  <pre><code>Select *
  FROM tableversion
  LEFT JOIN table(tableversion.month tableversion.year) on
      table(tableversion.month tableversion.year).Version_ID=tableversion.version_id
  </code></pre>
  
  <p>But in tableversion I've got months without leading 0 so i must check if there is 5 and then change it to 05, if variable is 12 then nothing. How can I do it?</p>
  
  <p>Ok, so now i have something like this</p>
  
  <pre><code>SELECT *, CONCAT('table',IF(tableversion.month &lt; 10, CONCAT('0', tableversion.month ), tableversion.month ),year) as year
  FROM tableversion
  LEFT JOIN year ON tableversion.version_id=year.version_id WHERE ADMIN_ID=11
  
  #1146 - Table 'database.year' doesn't exist
  </code></pre>
  
  <p>But it does not work</p>