Hi all,
Suppose my database table is looks like below table,
Id Date1 Name Type
1 2012-07-16 00:00:00.000 Rohit A
1 2012-07-16 00:00:00.000 Rohit A
1 2012-07-16 06:00:00.000 Rohit B
2 2012-07-16 08:00:00.000 Rahul A
2 2012-07-16 20:00:00.000 Rahul B
2 2012-07-16 21:00:00.000 Rahul B
In the above table, Two consecutive rows have the same name A then only last row should be display in the output table. AND I want a output like that:
Id Date1 Name Type
1 2012-07-16 00:00:00.000 Rohit A
1 2012-07-16 06:00:00.000 Rohit B
2 2012-07-16 08:00:00.000 Rahul A
2 2012-07-16 21:00:00.000 Rahul B
How can I do this? Please help me.
Rohatash
Loading


Dorababu MekaRank #457 · 5.5K reputationPosted Oct 4, 2012, 2:04 AM EDT
http://www.c-sharpcorner.com/Forums/Thread/183868/comparing-data-in-two-consecutive-rows-in-sql-server.aspx
Rohatash KumarRank #12 · 57.7K reputationPosted Oct 4, 2012, 2:07 AM EDT
Nuwan RathnayakeRank #2,612 · 534 reputationPosted Oct 4, 2012, 2:20 AM EDT
SELECT ID,DATE1,NAME,TYPE FROM table GROUP BY ID,DATE1,NAME,TYPE
Rohatash KumarRank #12 · 57.7K reputationPosted Oct 4, 2012, 2:31 AM EDT
Id Date1 Name Type
1 2012-07-16 00:00:00.000 Rohit A
1 2012-07-16 06:00:00.000 Rohit B
2 2012-07-16 08:00:00.000 Rahul A
2 2012-07-16 21:00:00.000 Rahul B