title: SELECT NEXT ROW, COMPARE, SET PREVIOUS ROW
body: <p>So I have a history table called <code>Member_Phys_History</code> in SQL-Server 2008</p>
  
  <p>Looks like this:</p>
  
  <pre><code>RecID, MemberID, Phys_ID, Phys_Start, Phys_End, Phys_Update
  </code></pre>
  
  <p>The first column is <code>identity</code>, the <code>Phys_Start</code>, <code>Phys_End</code>, and <code>Phys_Update</code> are dates.</p>
  
  <p>I have another table called <code>Member_Phys_Update</code></p>
  
  <pre><code>MemberID, Phys_ID, Phys_Start_Date
  </code></pre>
  
  <p>So once a week or so this Update table get's an update from client where The Phys_ID changes and the Phys_start is later in time...So I add this information to my History table and it would look like this:</p>
  
  <pre><code>1|ABC123|555|2014-01-01|NULL|NULL
  2|ABC123|556|2014-04-01|NULL|NULL
  </code></pre>
  
  <p><strong>Here's what I need to do:</strong></p>
  
  <p>I want to basically set the first records Phys_End_Date to the day before the second records <code>Phys_Start_Date</code>. So it would look like this:</p>
  
  <pre><code>1|ABC123|555|2014-01-01|2014-03-30|NULL
  2|ABC123|556|2014-04-01|NULL|NULL
  </code></pre>
  
  <p>I cannot use a stored procedure with a cursor unfortunately, my DBA says it's inefficient. I was wondering if there was any way I could do this in a couple queries...</p>
  
  <p>A cursor may be ideal, but can I do this with a FETCH NEXT or something? </p>