title: Dynamically create columns sql
body: <p>I have a table of Customers</p>
  
  <pre><code>Customer ID        Name         
     1               John        
     2               Lewis        
     3               Mary         
  </code></pre>
  
  <p>I have another table CustomerRewards</p>
  
  <pre><code> TypeID           Description
     1                Bronze
     2                Silver
     3                Gold
     4               Platinum
     5               AnotherOne
  </code></pre>
  
  <p>And the final table</p>
  
  <pre><code> RewardID          TypeID          CustomerID
      1                1                 1
      2                1                 1
      3                2                 1
      4                2                 2
  </code></pre>
  
  <p>The customerTypes table is dynamic, many of these types can be added and removed. Basically all I want is the columns to be generated dynamically and a count in each, something like</p>
  
  <pre><code>CustomerName        Bronze        Silver     Gold      Platinum     AnotherOne    total
     John               2             1         0           0             0           3
     Lewis              0             1         0           0             0           1
   Grand TOTAL          2             2         0           0             0           4
  </code></pre>
  
  <p>The problem like I said it that the types are dynamic and the customers are dynamic so I need the columns to be dynamic depending on the types in the system</p>
  
  <p>I have tagged c# as I need this in a DataGridView</p>
  
  <p>Thanks in advance</p>