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

Rohatash KumarPosted Oct 4, 2012, 6:31 AM
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
Nuwan RathnayakePosted Oct 4, 2012, 6:20 AM
SELECT ID,DATE1,NAME,TYPE FROM table GROUP BY ID,DATE1,NAME,TYPE
Rohatash KumarPosted Oct 4, 2012, 6:07 AM
Dorababu MekaPosted Oct 4, 2012, 6:04 AM
http://www.c-sharpcorner.com/Forums/Thread/183868/comparing-data-in-two-consecutive-rows-in-sql-server.aspx