title: calculate sum for values in SQL for display per month name
body: <p>i have a table with the following layout.</p>
  
  <pre><code>Email Blast Table
  
  EmailBlastId |  FrequencyId | UserId
  ---------------------------------
  1            |   5          |   1
  2            |   2          |   1
  3            |   4          |   1
  
  
  Frequency Table
  
  Id | Frequency 
  ------------
   1 |  Daily
   2 |  Weekly
   3 |  Monthly
   4 |  Quarterly
   5 |  Bi-weekly
  </code></pre>
  
  <p>I need to come up with a grid display on my asp.net page as follows.</p>
  
  <pre><code>Email blasts per month.
  
  UserId | Jan | Feb | Mar | Apr |..... Dec | Cumulative
  -----------------------------------------------------
  1        7      6     6     7          6     #xx
  </code></pre>
  
  <p>The only way I can think of doing this is as below, for each month have a case statement.</p>
  
  <pre><code>select SUM(
          CASE WHEN FrequencyId = 1 THEN 31 
          WHEN FrequencyId = 2 THEN 4
          WHEN FrequencyId = 3 THEN 1
          WHEN FrequencyId = 4 THEN 1
          WHEN FrequencyId = 5 THEN 2 END) AS Jan, 
        SUM(
          CASE WHEN FrequencyId = 1 THEN 28 (29 - leap year)
          WHEN FrequencyId = 2 THEN 4
          WHEN FrequencyId = 3 THEN 1
          WHEN FrequencyId = 4 THEN 0
          WHEN FrequencyId = 5 THEN 2 END) AS Feb, etc etc
  FROM EmailBlast 
  Group BY UserId
  </code></pre>
  
  <p>Any other better way of achieving the same?</p>