title: SQL continuous date range
body: <p>I'm stuck in something that looks simple in DB2, this is my table</p>
  
  <pre><code>ID  | BEG_DT                    | END_DT            
  ----  ------------------------- ------------------------- 
  
  1   |  2016-09-01 00:00:00.0    | 2016-09-30 00:00:00.0     
  2   |  2016-10-01 00:00:00.0    | 2016-10-31 00:00:00.0         
  3   |  2016-12-01 00:00:00.0    | 2016-12-31 00:00:00.0     
  4   |  2017-01-01 00:00:00.0    | 2017-01-31 00:00:00.0     
  5   |  2017-02-01 00:00:00.0    | 2017-02-28 00:00:00.0     
  6   |  2017-04-01 00:00:00.0    | 2017-04-30 00:00:00.0     
  7   |  2017-05-01 00:00:00.0    | 2017-05-31 00:00:00.0     
  8   |  2017-06-01 00:00:00.0    | 2017-06-30 00:00:00.0     
  9   |  2017-07-01 00:00:00.0    | null
  </code></pre>
  
  <p>I want a query that returns the continuous periods of begin date and end date, for example, in this case the query needs to return:</p>
  
  <pre><code>BEG_DT                    |END_DT            
  ------------------------- |------------------------- 
  2016-09-01 00:00:00.0     |2016-10-31 00:00:00.0     
  2016-12-01 00:00:00.0     |2017-02-28 00:00:00.0      
  2017-04-01 00:00:00.0     |null 
  </code></pre>