DannyLondon
Programmer
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.
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.