Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Select Prev/Next Record

Author  Topic 

taylo
Yak Posting Veteran

82 Posts

Posted - 2002-06-10 : 00:22:31
Does anyone know how to go about selecting the prev/next record in the database?

For example I am at record #100. I process it.
Now I want to get record 99 and 101. Obviously if records nenver got deleted this would be simple. I need a sure fire way to get the Prev/Next Identity records.

Thanks,


Rob

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2002-06-10 : 00:51:49
How about this for the next one:

SELECT TOP 1 *
FROM TableName
WHERE RecNum > 100
Order By RecNum ASC

and this for the previous one:

SELECT TOP 1 *
FROM TableName
WHERE RecNum < 100
Order By RecNum DESC

===============================================
Creating tomorrow's legacy systems today.
One crisis at a time.
Go to Top of Page

taylo
Yak Posting Veteran

82 Posts

Posted - 2002-06-10 : 00:56:25
You know I was going to try that......

Go to Top of Page
   

- Advertisement -