title: Update EndPeriodTime with next records StartPeriodTime
body: <p>I have a table with a StartPeriodTime and an EndPeriodTtime to help separate versions of the same account. When a new record is added for that particular account the previous record EndPeriodTime should be the StartPeriodTime of the new record.</p>
  
  <p>Currently it is not updating and I need to apply an update that will allow me to take care of this. The only EndPeriodTime that should be left as default should be the newest record. I have came up with code that works, but it is only working sometimes.</p>
  
  <p>If I was to load the table all at once with all my files it works great. If I was to load my table one file at a time it is failing because it is getting nulls. I need help writing this to where it doesn't pick up nulls. I am even open to writing it another way if someone can provide me with a workable solution. My code is below:</p>
  
  <pre><code>UPDATE ods.CustomerPayment
      SET EndPeriodTime = (
          SELECT MIN(t2.EndPeriodTime)
          FROM ods.CustomerPayment t2
          WHERE t2.CustomerNumber = t1.CustomerNumber
          AND t2.StartPeriodTime &gt; t1.StartPeriodTime
      )
  FROM ods.CustomerPayment t1
  WHERE t1.EndPeriodTime != '1999-01-01 00:00:00.000'
  </code></pre>