title: SQL Insert new columns in table B from rows of table A
body: <p>I am using Microsoft SQL Server.</p>
  
  <p><strong>Input</strong></p>
  
  <p>I have a table <code>Horizontal</code></p>
  
  <p><a href="https://i.stack.imgur.com/cZ37V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cZ37V.png" alt="enter image description here"></a></p>
  
  <p>and another table <code>Vertical</code></p>
  
  <p><a href="https://i.stack.imgur.com/nTugG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nTugG.png" alt="enter image description here"></a></p>
  
  <p>Desired output is shown in red.</p>
  
  <p>The aim is that each row of table horizontal is appended as a new column of table vertical. </p>
  
  <p>To be more specific:</p>
  
  <ul>
  <li>each row of column 'name' of table <code>Horizontal</code> will be the new column title of appended columns of table <code>Vertical</code>.</li>
  <li>each row of column 'value' of table <code>Horizontal</code> will be the new appended column rows of table <code>Vertical</code>.</li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/yCPed.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yCPed.png" alt="enter image description here"></a></p>
  
  <p>Thus, I would like to know how to implement the desired result in SQL (I use Microsoft SQL Server).</p>
  
  <p>Code:</p>
  
  <pre><code>CREATE TABLE HORIZONTAL 
  (
      id INT NOT NULL  PRIMARY KEY,
      NAME VARCHAR(40) NOT NULL,
      VALUE INT NOT NULL
  );
  
  INSERT INTO HORIZONTAL (id, name, value) 
  VALUES (1, 'jersey', 22), (2, 'newYork', 33);
  
  CREATE TABLE VERTICAL 
  (
      id INT NOT NULL PRIMARY KEY,
      PRODNAME VARCHAR(40) NOT NULL,
  );
  
  INSERT INTO VERTICAL (id, prodname) 
  VALUES (1, 'apple'), (2, 'orange'), (3, 'kiwi');
  </code></pre>