1)當(dāng)前頁:即要顯示或打開的那一頁的頁數(shù)
currPage
2)頁面大。杭疵宽撘@示數(shù)據(jù)的數(shù)量
如:每頁都顯示10條數(shù)據(jù)
pageSize
3)總數(shù)據(jù):要顯示的數(shù)據(jù)的總數(shù),即要顯示的結(jié)果集
totalSize
4)總頁數(shù):即顯示總數(shù)據(jù)需要的頁數(shù)
totalPage
它的計算公式為: (totalSize+pageSize-1)/pageSize
例如:
如要顯示17條數(shù)據(jù),每頁顯示5條,那么總頁數(shù): totalPage=(17+5-1)/5=4
5)計算當(dāng)前頁的第一條數(shù)據(jù) 計算公式:
(currPage-1)*pageSize+1
例如:
如要顯示17 條數(shù)據(jù),每頁顯示5條,那么第3頁數(shù)據(jù)第一條數(shù)據(jù)是:
(3-1)*5+1=11
6)計算當(dāng)前頁的最后一條數(shù)據(jù) 計算公式:
(currPage-1)*pageSize+pageSize
例如:
如要顯示17 條數(shù)據(jù),每頁顯示5條,那么第3頁數(shù)據(jù)最后一條數(shù)據(jù)是:
(3-1)*5+5=15
SQL SERVER 2005 實現(xiàn)分頁的方式
--------------------------------------------------------------------------------
一:存儲過程方式
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ù)編譯)
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;
三:按條件查詢后再對結(jié)果進行分頁
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;
注意:第一個where 用來匹配查詢條件;
第二個where 用來顯示特定頁數(shù)據(jù);