Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 24th, 2012  |  syntax: None  |  size: 0.78 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Group By Quarter and Month in SQL Server 2008
  2. Quarter  | Month  |  Group  |  Member  |  Value
  3. Q1 2011  | Jan    |  10     |  343     | 10
  4. Q1 2011  | Jan    |  1      |  3       | 10
  5. Q1 2011  | Jan    |  4      |  6       | 10
  6. Q1 2011  | Feb    |  34     |  33      | 10
  7. Q1 2011  | Feb    |  5      |  6       | 10
  8. Q1 2011  | Mar    |  54     |  33      | 10
  9. Q2 2011  | Apr    |  76     |  33      | 10
  10. Q2 2011  | May    |  98     |  33      | 10
  11. Q2 2011  | May    |  9      |  1       | 10
  12. ...
  13.        
  14. Quarter  | Month  |  Group  |  Member  |  Value
  15. Q1 2011  | Jan    |  15     |  352     | 30
  16. Q1 2011  | Feb    |  39     |  39      | 20
  17. ...
  18.        
  19. SELECT [Quarter], [Month], SUM([Group]) as [Group], SUM([Member]) as Member,
  20.   SUM([Value]) as [Value]
  21. FROM dbo.YourTableName
  22. GROUP BY [Quarter], [Month]