ramadesai108 (11/9/2009)
Thanks Paul and Gail for taking time. In this case what I will have to do is to insert the records into a temp table and thru a cursor check the previous Key value with the current one and if they are the same then insert the record into the temp table otherwise not. I was looking for a easier way, but i guess there is no easy way.
Am I alone in wondering how we were supposed to guess that from the original question? 😀
There are in fact easier ways - and a cursor is not required.
If you post some proper sample data and expected output, one of us will be sure to provide an awesome script for you. I'm a bit busy at work at the moment, but will try to look by later.
Solutions generally involve the ROW_NUMBER() window aggregate...
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi