title: Lead() and LAG() functionality in SQL Server 2008
body: <p>Hope all the SQL GURUS out there are doing great :) </p>
  
  <p>I am trying to simulate <code>LEAD()</code> and <code>LAG()</code> functionality in SQL Server 2008. </p>
  
  <p>This is my scenario: I have a temp table which is populated using the base query with the business logic for mileage. I want to calculate accumulated mileage for each user per day. </p>
  
  <p>The temp table is setup using <code>ROW_NUMBER()</code>, so I have all the data needed in the temp table except the accumulated mileage.</p>
  
  <p>I have tried using a CTE with the base query and self joining with itself and couldn't get it working. I am attaching the screen shot for the same. </p>
  
  <p>Any help/suggestion would be appreciated.  </p>