CREATE PROCEDURE pageTest --用于翻頁(yè)的測(cè)試 --需要把排序字段放在第一列 ( @FirstID nvarchar(20)=null, --當(dāng)前頁(yè)面里的第一條記錄的排序字段的值 @LastID nvarchar(20)=null, --當(dāng)前頁(yè)面里的最后一條記錄的排序字段的值 @isNext bit=null, --true 1 :下一頁(yè);false 0:上一頁(yè) @allCount int output, --返回總記錄數(shù) @pageSize int output, --返回一頁(yè)的記錄數(shù) @CurPage int --頁(yè)號(hào)(第幾頁(yè))0:第一頁(yè);-1最后一頁(yè)。 ) AS if @CurPage=0 begin --統(tǒng)計(jì)總記錄數(shù) select @allCount=count(ProductId) from Product_test set @pageSize=10 --返回第一頁(yè)的數(shù)據(jù) 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 --翻到下一頁(yè) select top 10 ProductId, ProductName, Introduction from Product_test where ProductId > @LastID order by ProductId else --翻到上一頁(yè) select * from (select top 10 ProductId, ProductName, Introduction from Product_test where ProductId < @FirstID order by ProductId desc) as bb order by ProductId end 百萬(wàn)數(shù)據(jù)翻頁(yè)就像100條數(shù)據(jù)一樣!
|