CREATE PROCEDURE pageTest --Test for page turning
--You need to put the sorting field in the first column
(
@FirstID nvarchar(20)=null, --The value of the sorting field of the first record in the current page
@LastID nvarchar(20)=null, --The value of the sort field of the last record in the current page
@isNext bit=null, --true 1: next page; false 0: previous page
@allCount int output, --Return the total number of records
@pageSize int output, --returns the number of records on one page
@CurPage int --Page number (page) 0: first page; -1 last page.
)
AS
if @CurPage=0
begin
--Statistical total number of records
select @allCount=count(ProductId) from Product_test
set @pageSize=10
--Return the data of the first page
select top 10
ProductId,
ProductName,
Introduction
from Product_test order by ProductId
end
else if @CurPage=-1
select * from
(select top 10 ProductId,
ProductName,
Introduction
from Product_test order by ProductId desc ) as aa
order by ProductId
else
begin
if @isNext=1
--turn to next page
select top 10 ProductId,
ProductName,
Introduction
from Product_test where ProductId > @LastID order by ProductId
else
--turn to previous page
select * from
(select top 10 ProductId,
ProductName,
Introduction
from Product_test where ProductId < @FirstID order by ProductId desc) as bb order by ProductId
end
Turning through millions of data pages is like 100 pieces of data!