title: Displaying the difference between rows in the same table in SQL SERVER
body: <p>I'm using SQL Server 2005.</p>
  
  <p>I have a table that has an archive of rows each time some field was changed.  I have to produce a report that displays fields that were changed for each employee. </p>
  
  <p>My table schema:</p>
  
  <pre><code>tblEmp(empid, name, salary, createddate)
  </code></pre>
  
  <p>My table data:</p>
  
  <pre><code>Row 1: 1, peter, 1000, 11/4/2012
  Row 2: 1, peter, 2000, 11/5/2012
  Row 3: 1, pete, 2000, 11/6/2012
  Row 4: 1, peter, 4000, 11/7/2012
  </code></pre>
  
  <p>Based on the above data for employee Peter (employee id 1), the output (changes) would be:</p>
  
  <p>resultset:</p>
  
  <pre><code>1, oldsalary: 1000 newsalary: 2000 (changed on 11/5/2012)
  1, oldname: peter newname: pete (changed on 11/6/2012)
  1, oldname: pete newname: peter, oldsalary:2000, newsalary: 4000 (changed on 11/7/2012)
  </code></pre>
  
  <p>I'm trying to come up with the sql that would produce the above resultset.</p>
  
  <p>I've tried to do something similar to the first answer in this thread: <a href="https://stackoverflow.com/questions/634568/how-to-get-difference-between-two-rows-for-a-column-field">How to get difference between two rows for a column field?</a></p>
  
  <p>However, it's not coming together, so wondering if anyone could help. </p>