• with cteTest (RowNum, EmpID, LogTime)

    as

    (

    select ROW_NUMBER() OVER(PARTITION BY EmployeeID ORDER BY LogTime ASC),

    EmployeeID,

    LogTime

    from #Test

    )

    select cc.EmpID,

    cc.LogTime

    from cteTest cc

    left join cteTest cp

    on cp.EmpID = cc.EmpID

    and cp.RowNum = cc.RowNum - 1

    where DATEDIFF(ss, coalesce(cp.LogTime, '01/01/01'), cc.LogTime) > 120

    order by cc.EmpID, cc.LogTime

    └> bt



    Forum Etiquette: How to post data/code on a forum to get the best help[/url]