title: SQL Server: group dates by ranges
body: <p>I have an SQL table with one column (dateRec) containing dates, format: yyyy-mm-dd. </p>
  
  <p>Is there a way in SQL that I can define date ranges and then group all the items by these ranges ?
  I would need the following groups here: </p>
  
  <ul>
  <li>group one = 0 - 7 days old</li>
  <li>group two = 8 - 14 days old</li>
  <li>group three = 15 - 30 days old</li>
  <li>group four = 31 - 60 days old</li>
  <li>group five = rest</li>
  </ul>
  
  <p><strong>My standard query to fetch all items from that table:</strong> </p>
  
  <pre><code>CREATE PROCEDURE [dbo].[FetchRequests]
  AS
  BEGIN
      SET NOCOUNT ON;
      SELECT      subject,
                  dateRec,
                  category
      FROM        LogRequests
      WHERE       logStatus = 'active'
      ORDER BY    dateRec desc, subject
      FOR XML PATH('items'), ELEMENTS, TYPE, ROOT('ranks')
  
  END
  </code></pre>
  
  <p>Thanks for any help with this, Tim.</p>