title: Find difference between two consecutive rows from a result in SQL server 2008
body: <p>I want to fetch the difference in &quot;Data&quot; column between two consecutive rows. For example, need Row2-Row1 ( 1902.4-1899.66) , Row 3-Row 2 and so on. The difference should be stored in a new column.</p>
  <pre><code>+----+-------+-----------+-------------------------+----+
  | Name      | Data       |meter|       Time             |
  +----+-------+-----------+-------------------------+----+
  | Boiler-1  |  1899.66   | 1   | 5/16/2019 12:00:00 AM  |
  | Boiler-1  |  1902.4    | 1   | 5/16/2019  12:15:00 AM |
  | Boiler-1  |  1908.1    | 1   | 5/16/2019  12:15:00 AM |
  | Boiler-1  |  1911.7    | 6   | 5/16/2019  12:15:00 AM |
  | Boiler-1  |  1926.4    | 6   | 5/16/2019  12:15:00 AM |
  | 
  +----+-------+-----------+-------------------------     +
  </code></pre>
  <p>Thing is the table structure that I have shown in the question, is actually obtained from two different tables. I mean, the above table is a result of a Select query to get data from two different tables. Goes like &quot;select name, data, unitId, Timestamp from table t1 join table t2.....&quot; So is there anyway for me to calculate the difference in &quot;data&quot; column value between consecutive rows, without storing this above shown result into a table?</p>
  <p>I use SQL 2008, so Lead/Lag functionality cannot be used.</p>