create proc P_Test--創建存儲過程P_Test
@pageSize int,--每頁數據條數
@pageIndex int,--當前頁數(頁碼)
@pageCount int output--總的頁數,因為需要顯示頁數,因此是個輸出參數
as
declare @datacount int--總數據條數
select @datacount=count(*) from test--獲得總數據條數值並賦給參數
set @pageCount=ceiling(1.0*@datacount/@pageSize)--獲得總頁數,並賦給參數
--接下來是獲得指定頁數據
select * from
(select *,row_number() over(order by Test1) as num from test) as temp
where num between @pageSize*(@pageIndex-1)+1 and @pageSize*@pageIndex