title: Can I use a MySQL variable to name a table?
body: <p>I've got a workflow that requires me to keep a bunch of tables with different names like</p>
  
  <pre><code>2012_10_15_ncvoter68
  2012_11_15_ncvoter68
  2012_12_15_ncvoter68
  </code></pre>
  
  <p>You get the idea.</p>
  
  <p>Let's say that I've just created the table <code>2012_12_15_ncvoter68</code>.</p>
  
  <p>I would like to query this table using a variable. E.g., I could define a variable:</p>
  
  <pre><code>SET @dt_ncv = CONCAT((SELECT DATE_FORMAT(CURDATE(), '%Y_%m_%d')),"_ncvoter68");
  </code></pre>
  
  <p>The variable <code>@dt_ncv</code> evaluates to the string <code>2012_12_15_ncvoter68</code>.</p>
  
  <p>But I can't figure out how (or if it's possible) to use this variable to reference the table.</p>
  
  <p>The query:</p>
  
  <pre><code>SELECT count(*) FROM @dt_ncv;
  </code></pre>
  
  <p>simply give a SQL syntax error.</p>
  
  <p>I've tried playing with prepared statements but that didn't seem to help.</p>
  
  <p>I hope some of you MySQL gurus can help!</p>