How to select data from multiple tables where table name is value from a column of another table?
<p>I have a table consists of table name, for example:</p>

<p>TableA</p>

<pre><code>    UID  TableName  CifKey  ...
    1     xxx       12345
    1     yyy       12345
    1     xxx       12345
    2     zzz       45678
</code></pre>

<p>How can I select data from tables that having name same as the <code>TableName</code> column in Table A?</p>

<p>For example:</p>

<pre><code>SELECT A.a, B.b 
FROM TableA A 
JOIN ' + @TableName + ' B ON A.Cifkey = B.Cifkey 
WHERE A.uid = @uid AND A.cifkey = @cifkey
</code></pre>

<p>Thank you!</p>