title: How do I do a join in SQL based on table name?
body: <p>Ok, so we have a bunch of tables that are named like this:</p>
  
  <pre><code>training_data_001
  training_data_002
  training_data_003
  training_data_004
  training_data_005
  </code></pre>
  
  <p>And then to find those we look at a field in another table, let's just call it master.training_type.</p>
  
  <p>Anyway, I was wondering if anyone knew of a way to do a weird table name based join with this kind of data.  Something like this:</p>
  
  <pre><code>SELECT foo FROM master WHERE id = ? 
  INNER JOIN training_data_${master.training_type}
  ON foo.id = training_data_${master.training_type}.foo_id
  </code></pre>
  
  <p>I know that I can do this on the client side, but it would be nice to have the db do it.</p>
  
  <p>Also note: it's SQL Server.</p>
  
  <p><strong>Update</strong>: I decided to just do it on the client side.  Thanks anyway everyone.</p>
  
  <p>Thanks!</p>
  
  <p>-fREW</p>