the Id controls which is before and after? If so then yes you can do thisDECLARE @foo TABLE ( [ID] INT , [val] DATETIME )INSERT @foo ([ID], [val]) SELECT 1, '2009-01-01 00:00:00'UNION SELECT 2, '2009-01-01 12:00:00'UNION SELECT 3, '2009-01-01 13:50:14'SELECT a.[ID] , a.[val] AS [Record Timestamp] , b.[val] AS [Prev Record Timestamp] , ABS(DATEDIFF(SECOND, a.[val], b.[val])) AS [Difference (Seconds)]FROM @foo a LEFT JOIN @foo b ON b.[Id] = a.[Id] - 1
If the ID sequence has gaps in it you can use a Common table expression with a ROW_NUMBER() column to get an unbroken sequence.All the best.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION