5
Reply

Comparing Data in Two Consecutive Rows in SQL Server

Rohatash Kumar

Rohatash Kumar

Aug 21 2012 11:42 PM
3.9k
Suppose my database table is looks like below table,

Id               Name    Status

2012-07-16    A        Login
2012-07-16    A        Logout
2012-07-16    A        Login
2012-07-16    A        Login
2012-07-16    A        Logout

In the above table, Two consecutive rows have the same name login then only last row should be display in the output table. AND I want a output like that:

Date            Name     Status

2012-07-16    A          Login
2012-07-16    A          Logout
2012-07-16    A          Login
2012-07-16    A          Logout

How can I do this?  Please help me.

Answers (5)