If I have 100 records, how can I use SQL Server's segmented query to display 10 records per page and 10 pages?
I:
Select top 10 * from table where primary key not in (select top 10 * (page-1) primary key from table)
In this case, the table is the name of your table. The primary key is the primary key field of the table. The number of pages should be dynamically set. You can determine the number of pages based on the pages and change them accordingly.
II:
Assume that the primary key column is ID
Select top 10 * from Table order by ID (first page, first 10)
Each time the next page is followed, an incremental number is required to determine the page number ~ Assume it is A, the second page is 1, and the third page is 2
Select top 10 * from table whereIDNot in (select top 10 *
IDFrom table order by ID)
The two red values must correspond to each other. Otherwise, the error"Only one expression can be specified in the select list when the subquery is not introduced
With exists."
Original article address