title: Calculation of total duration of events for a day
body: <p>We have a table called Events, with columns Id(int), EventDate(DateTime), EventStart(datetime) and EventEnd(datetime).</p>
  
  <p>All events start and end on a single day (i.e. no events end the next day), however events in a given date may overlap between them (including one of them could cover another entirely). </p>
  
  <p>Any number of events may occur for a given date.</p>
  
  <p>I would like to, for a single day calculate the total duration during which at least one event was running in T-SQL. I can select the events on a given date, and have even written a function returning true if two events are overlapping and false if not.</p>
  
  <p>I am stuck however in how to take the records in pairs and run them through my function, adding the durations appropriately until I run out of events. </p>
  
  <p>Can you help? </p>
  
  <p>Chris</p>