Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning rows n-m without RowNum

Status
Not open for further replies.

DannyLondon

Programmer
Nov 19, 2002
33
GB
I have a requirement to present 20 records at a time on an ASP page. I was dismayed to find there is no RowNum, as there is in Oracle, and so came up with the following logic. I hope this may be useful to some others.

The example will return rows 61-80. The starting record (61), and number of records (20) can be passed as parameters. The table Accounts has a column AccountCode.

SELECT TOP 20
AccountCode
FROM Accounts
WHERE AccountCode > (SELECT MAX(AccountCode)
FROM (SELECT TOP 61 AccountCode
FROM Accounts
ORDER
BY AccountCode) Codes)
ORDER
BY AccountCode

Please let me know if you can identify any weaknesses or improvements.
 
Oops...

The > should be replaced by >=.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top