title: Comparing Two Sets of Date Ranges in SQL
body: <p>I have two sets of data with different date ranges.</p>
  
  <pre><code>Tbl 1:  
  ID, Date_Start, Date_End
  1, 2010-01-01, 2010-01-09
  1, 2010-01-10, 2010-01-19
  1, 2010-01-30, 2010-01-31
  
  Tbl 2:
  ID, Date_Start, Date_End
  1, 2010-01-01, 2010-01-04
  1, 2010-01-08, 2010-01-17
  1, 2010-01-30, 2010-01-31
  </code></pre>
  
  <p>I'd like to find cases date ranges do not entirely overlap date ranges in Tbl 2.  So for instance, in this example, I'd like output that looks something like this --</p>
  
  <pre><code>Output:
  ID, Gap_Start, Gap_End
  1, 2010-01-05, 2010-01-07
  1, 2010-01-18, 2010-01-19
  </code></pre>
  
  <p>Date ranges will never overlap within a table.  To do this, I'm using either DB2 SQL or SAS.  Unfortunately, the datasets are big enough (millions of records) that I can't just brute force it.</p>
  
  <p>Thank you!</p>