title: T-SQL combine periods
body: <p>here is the example table with data (rn column is ROW_NUMBER() for each UELN).</p>
  
  <pre><code>UELN            OwnerID Date                    rn
  191001180010389 017581  1989-06-30 00:00:00.000 1
  191001180010389 017747  2011-06-02 00:00:00.000 2
  191001180010389 017992  2014-03-25 00:00:00.000 3
  191001180010389 117030  2015-02-03 00:00:00.000 4
  191001250009303 018148  2004-06-30 00:00:00.000 1
  191001250009303 018418  2013-10-16 00:00:00.000 2
  </code></pre>
  
  <p>I need to combine those rows to get result set like this:</p>
  
  <pre><code>UELN            OwnerID DateFrom                DateTo
  191001180010389 017581  1989-06-30 00:00:00.000 2011-06-02 00:00:00.000
  191001180010389 017747  2011-06-02 00:00:00.000 2014-03-25 00:00:00.000
  191001180010389 017992  2014-03-25 00:00:00.000 2015-02-03 00:00:00.000
  191001180010389 117030  2015-02-03 00:00:00.000 NULL
  191001250009303 018148  2004-06-30 00:00:00.000 2013-10-16 00:00:00.000
  191001250009303 018418  2013-10-16 00:00:00.000 NULL
  </code></pre>
  
  <p>NULL in DateTo column means that this is still valid.</p>
  
  <p>Can anyone help me with the query?</p>