title: Get rows of table as columns in second table
body: <p>I apologize in advance if this question has been asked before.</p>
  
  <p>I have two tables. Table one has three columns <code>CustomerID, SequenceNum, Value</code>, table two has a large amount of columns. I would like to fill in the columns of table two with the values of table one by column, not by row.</p>
  
  <p>An example:</p>
  
  <pre><code>------------------------------------
  | CustomerID | SequenceNum | Value |
  ------------------------------------
  |      1     |      1      |   A   |
  ------------------------------------
  |      1     |      2      |   B   |
  ------------------------------------
  |      1     |      3      |   C   |
  ------------------------------------
  |      2     |      1      |   Q   |
  ------------------------------------
  |      2     |      2      |   R   |
  ------------------------------------
  |      3     |      1      |   X   |
  ------------------------------------
  </code></pre>
  
  <p>becomes</p>
  
  <pre><code>---------------------------------------------------------------------
  | CustomerID | PrimaryVal | OtherVal1 | OtherVal2 | OtherVal3 | ... |
  ---------------------------------------------------------------------
  |      1     |      A     |     B     |     C     |    NULL   | ... |
  ---------------------------------------------------------------------
  |      2     |      Q     |     R     |    NULL   |    NULL   | ... |
  ----------------------------------------------------------------------
  |      3     |      X     |    NULL   |    NULL   |    NULL   | ... |
  ---------------------------------------------------------------------
  </code></pre>
  
  <p>In essence. Each unique <code>CustomerID</code> in table one will have a single row in table two. Each <code>SequenceNum</code> of a particular <code>CustomerID</code> will fill in a column in table two under <code>PrimaryVal, OtherVal1, OtherVal2, etc.</code>. A row which has a <code>SequenceNum</code> equal to 1 will fill the <code>PrimaryVal</code> field, and 2-18 (the maximum sequence length is 18) will fill <code>OtherVal#</code>.</p>
  
  <p>The main problem I see is the variable amount of values in a sequence. Some sequences may only contain 1 row, some will fill up all 18 spots, and anything in between.</p>
  
  <p>Any advice on how to solve this problem would be greatly appreciated. Thank you.</p>