DataGrid connection ACCESS fast paging method (3) - SQL statement selection (descending)
Third, descending
(1)
@PageIndex
<=
@FirstIndex
Select Top @Pagesize @Queryfields
From @tablename
Where @condition
Order by @primaryKey DESC
(2)
@FirstIndex
<
@PageIndex
<=
@MIDDleIndex
Select Top @Pagesize @Queryfields
From @tablename
Where @PrimaryKey
<(
SELECT MIN
(
@PrimaryKey
)
From
(
Select Top @PageSize
*
@PageIndex @PrimaryKey
From @tablename
Where @condition
Order by @primaryKey DESC
TABLEA
)
Where @condition
Order by @primaryKey DESC
(3)
@MIDDleIndex
<
@PageIndex
<
@LastIndex
SELECT
*
From
(
Select Top @Pagesize @Queryfields
From @tablename
Where @PrimaryKey
> (
SELECT MAX
(
@PrimaryKey
)
From
(
SELECT TOP
(
@Recordcount
-
@PageSize
*
@PageIndex
1
))
@PrimaryKey
From @tablename
Where @condition
- Order by @PrimaryKey ASC
TABLEA
)
Where @condition
- Order by @PrimaryKey ASC
Tableb
Order by @primaryKey DESC
(4)
@PageIndex
> =
@LastIndex
SELECT
*
From
(
SELECT TOP
(
@Recordcount
-
@PageSize
*
@LastIndex
)
@Queryfields
From @tablename
Where @condition
Order by @primaryKey ASC
TABLEA
Order by @primaryKey DESC
Fourth, summary
Through the discussion above, I believe that everyone should see the advantages of this paging method. In the next article, I will give you a class that dynamically generates the class above the SQL statement.
Author: Tripoli