Advertisement
Guest User

Gaps reporting

a guest
Jun 4th, 2015
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.47 KB | None | 0 0
  1.  
  2.         SELECT [RespondentId], [StartDateTime], [EndDateTime]
  3.     INTO [tmp].[RESULT]
  4.     FROM (
  5.         SELECT [RespondentId], [StartDateTime], [EndDateTime]
  6.             FROM
  7.             (
  8.                 SELECT  [RespondentId],
  9.                         [EndDateTime] AS [StartDateTime],
  10.                         LEAD(StartDateTime) OVER (PARTITION BY [RespondentId] ORDER BY [StartDateTime]) AS [EndDateTime]
  11.                 FROM @INPUT
  12.             ) A
  13.         WHERE [A].[EndDateTime] IS NOT NULL
  14.           ) AS B
  15.     WHERE ABS(DATEDIFF(mi, [EndDateTime], [StartDateTime])) <= @GapSize
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement