1)當(dāng)前頁(yè):即要顯示或打開(kāi)的那一頁(yè)的頁(yè)數(shù)
currPage
2)頁(yè)面大。杭疵宽(yè)要顯示數(shù)據(jù)的數(shù)量
如:每頁(yè)都顯示10條數(shù)據(jù)
pageSize
3)總數(shù)據(jù):要顯示的數(shù)據(jù)的總數(shù),即要顯示的結(jié)果集
totalSize
4)總頁(yè)數(shù):即顯示總數(shù)據(jù)需要的頁(yè)數(shù)
totalPage
它的計(jì)算公式為: (totalSize+pageSize-1)/pageSize
例如:
如要顯示17條數(shù)據(jù),每頁(yè)顯示5條,那么總頁(yè)數(shù): totalPage=(17+5-1)/5=4
5)計(jì)算當(dāng)前頁(yè)的第一條數(shù)據(jù) 計(jì)算公式:
(currPage-1)*pageSize+1
例如:
如要顯示17 條數(shù)據(jù),每頁(yè)顯示5條,那么第3頁(yè)數(shù)據(jù)第一條數(shù)據(jù)是:
(3-1)*5+1=11
6)計(jì)算當(dāng)前頁(yè)的最后一條數(shù)據(jù) 計(jì)算公式:
(currPage-1)*pageSize+pageSize
例如:
如要顯示17 條數(shù)據(jù),每頁(yè)顯示5條,那么第3頁(yè)數(shù)據(jù)最后一條數(shù)據(jù)是:
(3-1)*5+5=15
SQL SERVER 2005 實(shí)現(xiàn)分頁(yè)的方式
--------------------------------------------------------------------------------
一:存儲(chǔ)過(guò)程方式
if exists(select * from sysobjects where name='pro_pageData')
drop procedure pro_pageData
go
create procedure pro_pageData
@pageNum int
as
select *
from
(
select *, row_number() over (order by stuid) as rowno
from student
) as s
where rowno>=(@pageNum-1)*5+1 and rowno <= (@pageNum -1)*5+5;
go
exec pro_pageData 4
go
二:一般語(yǔ)句方式(預(yù)編譯)
select *
from
(
select *, row_number() over (order by stuid) as rowno
from student
) as s
where rowno>=(?-1)*5+1 and rowno <= (?-1)*5+5;
三:按條件查詢(xún)后再對(duì)結(jié)果進(jìn)行分頁(yè)
select *
from
(
select *, row_number() over (order by stuid) as rowno
from student
where 1=1 and stuName like '%羅%'
) as s
where rowno>=(1-1)*5+1 and rowno <= (1 -1)*5+5;
注意:第一個(gè)where 用來(lái)匹配查詢(xún)條件;
第二個(gè)where 用來(lái)顯示特定頁(yè)數(shù)據(jù);