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 2008 Forums
 Transact-SQL (2008)
 Select Top n, then next n

Author  Topic 

kpgraci
Yak Posting Veteran

68 Posts

Posted - 2010-09-23 : 09:54:30
Hi all,

I want to page through a large number of records so I display only, say, 20 at a time.

I can get the first 20 with

SELECT TOP 20 F1, F2 FROM TABLE ORDER BY F1

But how can I get the next (and previous) set of records?

For example, I may want records 60-80 as ordered by field F1.

Worst case I can query the TOP 80 in this case and only return the last 20 (since this is being called via a web service I'm writing) but that would not be very efficient for records 10,000 to 10,020.

Thanks!


kpg

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-09-23 : 09:59:53
Start here: lots of info on this:
http://www.sqlteam.com/article/server-side-paging-using-sql-server-2005

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -