title: Group data in monthly report using start date and end date
body: <p>I have a table called <code>tours</code> in which I have following fields </p>
  
  <pre><code>tourId, tourStartDate, tourEndDate , tourDetail ,deptCode,targetYear, and officerName
  </code></pre>
  
  <p>Now i want to summarize my data into months 
  so result table should look like by following schema </p>
  
  <pre><code>declare @temp table (
    id int identity(1,1) not null,
    officerName, 
    jan int ,feb int,
    march int,april int, 
    may int,
    june int ,
    july int, 
    aug int,
    sep int, 
    oct int, 
    nov int, 
    dec int
  );
  select * from  @temp
  </code></pre>
  
  <p>I tried with <code>with cte</code> to traverse each row and using case to insert in temporary table but its not look like good solution so any clue or guide really help me a lot. </p>
  
  <p><strong>count of tours done by officer in that month will appear in month column as value</strong> </p>
  
  <p><strong>EDITED</strong></p>
  
  <p>A tour with starting date in jan and ending date in some other month, say feb then its value will appear in both month </p>