title: Alternate of lead lag function in SQL Server 2008
body: <p>I want to compare the current row with a value in the next row. SQL has <code>LEAD</code> and <code>LAG</code> functions to get the next and previous values but I can not use them because I am using SQL Server 2008.</p>
  
  <p>So how do I get this?</p>
  
  <p>I have table with output</p>
  
  <pre><code>+----+-------+-----------+-------------------------+
  | Id | ActId |  StatusId |       MinStartTime      |
  +----+-------+-----------+-------------------------+
  | 1  |  42   | 1         | 2014-02-14 11:17:21.203 |
  | 2  |  42   | 1         | 2014-02-14 11:50:19.367 |
  | 3  |  42   | 1         | 2014-02-14 11:50:19.380 |
  | 4  |  42   | 6         | 2014-02-17 05:25:57.280 |
  | 5  |  42   | 6         | 2014-02-19 06:09:33.150 |
  | 6  |  42   | 1         | 2014-02-19 06:11:24.393 |
  | 7  |  42   | 6         | 2014-02-19 06:11:24.410 |
  | 8  |  42   | 8         | 2014-02-19 06:44:47.070 |
  +----+-------+-----------+-------------------------+
  </code></pre>
  
  <p>What I want to do is if the current row status is 1 and the next row status is 6 and both times are the same (up to minutes) then I want to get the row where the status is 1.</p>
  
  <p>Eg: Id 6 row has status 1 and Id 7 row has status 6 but both times are the same ie. 2014-02-19 06:11</p>
  
  <p>So I want to get this row or id for status 1 ie. id 6</p>