title: Convert Rows to columns using 'Pivot' in SQL Server
body: <p>I have read the stuff on MS pivot tables and I am still having problems getting this correct.</p>
  
  <p>I have a temp table that is being created, we will say that column 1 is a Store number, and column 2 is a week number and lastly column 3 is a total of some type. Also the Week numbers are dynamic, the store numbers are static.</p>
  
  <pre><code>Store      Week     xCount
  -------    ----     ------
  102        1        96
  101        1        138
  105        1        37
  109        1        59
  101        2        282
  102        2        212
  105        2        78
  109        2        97
  105        3        60
  102        3        123
  101        3        220
  109        3        87
  </code></pre>
  
  <p>I would like it to come out as a pivot table, like this:</p>
  
  <pre><code>Store        1          2          3        4        5        6....
  ----- 
  101        138        282        220
  102         96        212        123
  105         37        
  109
  </code></pre>
  
  <p>Store numbers down the side and weeks across the top.</p>