A SQL statement to get a database page

zhaozj2021-02-17  34

A statement to get the database page

Select Top 10 b. * from (SELECT TOP 20 Primary button, Sort FROM Name ORDER BY Sort Field DESC) A, Table Name B WHERE B. Primary Key Field = a. Primary key field Order By a. Sort field

10 = number of records per page

20 = (current page 1) * Per page record number

The above statement can achieve paging, but the resulting sequence of the last removed is ascended, and if the result set is designed (for example, time), there are two ways to process.

1. Use the following statement, but efficiency may reduce some

SELECT * FROM table name B, (SELECT TOP 10 primary key field, sort field from (SELECT TOP 20 Primary key field, sort field from Name ORDER BY Sort Field DESC) a ORDER BY Sort Field) c where b. Primary key field = C. Master key field Order by c. Sort field DESC

2. Handled in ADO, move the recordset to the last, then move forward

'' The following is an ASP example

Set Rstemp = Server.createObject ("AdoDb.Recordset")

RSTEMP.Open statement, conn, 1, 1

Rstemp.movelast

For i = 1 to Rstemp.Recordcount

'Review ....

RSTemp.MovePrevious

NEXT

After testing, the above paging method is fast than the use of temporary tables, and is easy to use

Original article, 2004.5.26 first in the 9CBS Document Center, please indicate the source, thank you

Welcome to contact if there is a problem

转载请注明原文地址:https://www.9cbs.com/read-30533.html

New Post(0)