title: Quick way to compare differences between ordered SQL records
body: <p>I have a SQL query with first column being the date, and second and third column being some other info. We can assume there is only one record for every day, and we can assume the dates are ordered.</p>
  
  <p>Besides the first column, others contain data of different data types <code>long</code>, <code>int</code>, <code>nchar</code>, <code>varchar</code>, etc.</p>
  
  <p>My goal is to figure out if any of the remaining columns have changed on day T when compared versus day T-1, if so (say column N is changed, N could be any of the remaining columns and there might be multiple columns being changed on the same day) I would like to return the date (first column) together with the records on Col N as of Day T versus Col N as of day T-1 (and potentially the header of that column), so my output would be:</p>
  
  <pre><code>Date T|Header of Col Modified|Value of Col @ T-1|Value of Col @ T
  </code></pre>
  
  <p>If there are multiple changes, we'll have one row for each change.</p>
  
  <p>Obviously the "slow" way is to bring all the data in somewhere first and then compare the resulting dataset one by one. However I am just wondering if there is any quick way to do it in T-SQL so that I can directly get the result (or something close to the results so that little data manipulation is needed with the output from the query, since it would be much faster for the SQL Server to do the heavy lifting and return only the data I need rather than pretty much the entire table.</p>
  
  <p>I am using SQL Server so a solution in T-SQL is needed.</p>