title: SQL query to calculate days worked per Month
body: <p>Im stuck on a SQL query. Im using SQL Server.</p>
  
  <p>Given a table that contains Jobs with a start and end date. These jobs can span days or months. I need to get the total combined number of days worked each month for all jobs that intersected those months.</p>
  
  <p>Jobs</p>
  
  <pre><code>-----------------------------------
  JobId | Start  | End    | DayRate |
  -----------------------------------
  1     | 1.1.13 | 2.2.13 | 2500    |
  2     | 5.1.13 | 5.2.13 | 2000    |
  3     | 3.3.13 | 2.4.13 | 3000    |
  </code></pre>
  
  <p>The results i need are:</p>
  
  <pre><code>Month | Days
  --------------
  Jan   | 57
  Feb   | 7
  Mar   | 28
  Apr   | 2
  </code></pre>
  
  <p>Any idea how i would right such a query ?</p>
  
  <p>I would also like to work out the SUM for each month based on multiplying the dayrate by number of days worked for each job, how would i add this to the results ?</p>
  
  <p>Thanks</p>