title: Select data from one table & then rename the columns based on another table in SQL server
body: <p>I have two tables. <code>TableOne</code> which contains two columns (name &amp; value). <code>TableTwo</code> can contain <code>N no. of columns</code>. Number of rows in <code>TableOne</code> will be equal to number of columns in <code>TableTwo</code>. </p>
  
  <p>see the below image for more information. </p>
  
  <p><img src="https://i.stack.imgur.com/GczPV.png" alt="enter image description here"></p>
  
  <p><strong>What I want:</strong></p>
  
  <p>When I run select query on <code>TableTwo</code>, the result-set should pick the column names based on <code>value</code> column of <code>TableOne</code>. We need to match column name of <code>TableTwo</code> with rows available in <code>TableOne</code> and perform transform.</p>
  
  <p>So the output should look like this:</p>
  
  <pre><code>ColumnOne | ColumnTwo | columnThree | ColumnFour
  
   1           1            1             2015-05-08 15:28:22.630
   2           2            2             2015-05-07 15:28:22.630
   ................
   ................
  </code></pre>