title: Get count based on 15 minutes of interval
body: <p>I am working with SQL Server 2008 R2, I have a table:</p>
  
  <p><strong>tbl_calls</strong></p>
  
  <pre><code>cl_Id
  cl_StartDate
  cl_endDate
  </code></pre>
  
  <p>I am passing two parameters <code>@StartDate</code> and <code>@EndDate</code> to my stored procedure.</p>
  
  <p>My requirement is to get count of records between every 15 minutes of duration</p>
  
  <p>Example:</p>
  
  <pre><code>@StartDate = '2015-11-16 00:00:00.000', 
  @EndDate = '2015-11-16 23:59:00.000'
  </code></pre>
  
  <p>Output should be:</p>
  
  <pre><code>Date                        Count
  2015-11-16 00:00:00.000      10(Count of startDate between '2015-11-16 00:00:00.000' AND '2015-11-16 00:15:00.000')
  2015-11-16 00:15:00.000       7(Count of startDate between '2015-11-16 00:15:00.000' AND '2015-11-16 00:30:00.000')
  2015-11-16 00:30:00.000      50(Count of startDate between '2015-11-16 00:30:00.000' AND '2015-11-16 00:45:00.000')
  
  upto @EndDate
  </code></pre>
  
  <p>I tried to do it but not getting idea, i am not sure below query is nearby to logic or not.</p>
  
  <p>What I tried is :</p>
  
  <pre><code>DECLARE @StartDate DATETIME = DATEADD(DAY,-1,GETUTCDATE()),
          @EndDate DATETIME = GETUTCDATE()
  
  SELECT New 
  FROM
      (SELECT 
           (CASE 
               WHEN cl_StartTime BETWEEN @StartDate AND DATEADD(MINUTE, 15, @StartDate) 
                  THEN 1 
                  ELSE 0 
            END) AS New 
       FROM          
           tbl_Calls WITH (NOLOCK)    
       WHERE 
           cl_StartTime BETWEEN @StartDate AND @EndDate) AS Inners 
  GROUP BY 
      New
  </code></pre>
  
  <p>Let me know if you need further details.</p>
  
  <p>Thank you.</p>