Pages

Tuesday, October 5, 2010

TSQL - Find date difference between two rows

SQL 2005

WITH TableWithKey AS

ROW_NUMBER
(SELECT tagid, Time_Stamp, () OVER (ORDER BY tagid, Time_Stamp) AS ExtraKeyFROM TAZMReads) SELECT a.tagid, a.Time_Stamp FROM TableWithKey AS a INNER
JOIN TableWithKey AS b ON b.ExtraKey = a.ExtraKey - 1 and a.tagid = b.tagid and

DATEDIFF(Second, b.Time_Stamp, a.Time_Stamp) > 1

No comments:

Post a Comment