title: SQL Server Count number of overlaps (date ranges)
body: <p>I have a table which stores vehicles and the dates they are rented out. I would like to find out if the dates overlap and the count of overlaps for a vehicle in SQL Server 2008. The result I am expecting is as follows.</p>
  
  <pre><code>ID  Vehicle     StartDate   EndDate     Overlap
  ==============================================================
  1   Ford Focus  01/01/2014  31/01/2014  1
  2   Ford Focus  20/01/2014  20/02/2014  1
  3   Ford Focus  01/03/2014  28/03/2014  0
  4   Mercedes    18/03/2014  24/03/2014  0
  5   Mercedes    01/07/2014  31/07/2014  2
  6   Mercedes    15/07/2014  31/07/2014  2
  7   Mercedes    25/07/2014  25/08/2014  2
  </code></pre>