title: Grouping By Time Range
body: <p>I have data as below:</p>
  
  <pre><code>Name    StartTime    EndTime  
  ABC      10:00       10:21
  BCC      10:00       10:01
  BCD      10:11       10:16
  DFF      10:20       10:21
  </code></pre>
  
  <p>Now first I need a total count for all activities for every 5 minutes within start time anf end time from on the hour which I only have got by the start time as following :</p>
  
  <pre><code>SELECT Time,
  COUNT(*) as [Count]
  FROM
  (SELECT CONVERT(CHAR(5),
  DATEADD(MINUTE,
  FLOOR(DATEDIFF(MINUTE,'20000101',StartTime)/5.0)*5
  ,'20000101'),108)
  FROM tableName) AS Time(Time)
  GROUP BY Time
  </code></pre>
  
  <p>This gives me my totals every 5 mins as below :</p>
  
  <pre><code>10:00 2 (between 10:00 and 10:04:59)
  10:05 0 
  10:10 1
  10:15 0
  etc.....
  </code></pre>
  
  <p>Now I need to count the activities between start time and end time</p>
  
  <pre><code>10:00 2 (between 10:00 and 10:04:59)
  10:05 1 
  10:10 2
  10:15 2
  etc.....
  </code></pre>