title: SQL Query Comparing datetime overlaps and displaying them
body: <p>I have directors that pay helpers based on if the helper worked or not when the director did.</p>
  
  <p>Have 2 views as follows:-</p>
  
  <p><strong>Director</strong></p>
  
  <pre><code>Name    TimeIn                      TimeOut
  
  Bob     2012-07-17 07:00:00.000     2012-07-17 16:00:00.000
  Sam     2012-07-17 10:00:00.000     2012-07-17 20:00:00.000
  Beatly  2012-07-17 14:00:00.000     2012-07-17 23:00:00.000
  Mac     2012-07-17 21:00:00.000     2012-07-18 07:00:00.000 
  </code></pre>
  
  <p><strong>Helper</strong></p>
  
  <pre><code>Name    TimeIn                      TimeOut
  Fred    2012-07-17 15:59:00.000     2012-07-18 00:19:00.000
  </code></pre>
  
  <p>Now figuring out who worked during that time isn't the hard part, or at least it isn't the part I am having an issue wrapping my brain around. What is is finding where and what mins and by who this overlap by the min. And group them together by the time used. Because they will all split the hourly pay with the scribe. So ideally the following would be the result.</p>
  
  <pre><code>DirName HelperStart                 HelperEnd
  Bob     2012-07-17 15:59:00.000     2012-07-17 16:00:00.000
  Sam     2012-07-17 15:59:00.000     2012-07-17 16:00:00.000
  Beatly  2012-07-17 15:59:00.000     2012-07-17 16:00:00.000
  Sam     2012-07-17 16:01:00.000     2012-07-17 20:00:00.000
  Beatly  2012-07-17 16:01:00.000     2012-07-17 20:00:00.000
  Beatly  2012-07-17 20:01:00.000     2012-07-17 21:00:00.000
  Beatly  2012-07-17 21:01:00.000     2012-07-17 23:00:00.000
  Mac     2012-07-17 21:01:00.000     2012-07-17 23:00:00.000
  Mac     2012-07-17 23:01:00.000     2012-07-18 00:19:00.000
  </code></pre>
  
  <p>Using SQL server 2008. I hope the bare bones simple breakdown is enough. Found enough queries to see if someone conflicts with the time, but no breakdown of the above.</p>