西西軟件園多重安全檢測下載網(wǎng)站、值得信賴的軟件下載站!
軟件
軟件
文章
搜索

首頁西西教程數(shù)據(jù)庫教程 → 數(shù)據(jù)查詢分頁的相關(guān)概念 分頁的存儲過程

數(shù)據(jù)查詢分頁的相關(guān)概念 分頁的存儲過程

相關(guān)軟件相關(guān)文章發(fā)表評論 來源:本站整理時間:2011/2/14 21:17:14字體大。A-A+

作者:佚名點擊:65次評論:1次標(biāo)簽: 分頁

  • 類型:濾鏡插件大小:3.7M語言:英文 評分:5.0
  • 標(biāo)簽:
立即下載
 分頁的相關(guān)概念:

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ù);

    相關(guān)評論

    閱讀本文后您有什么感想? 已有人給出評價!

    • 8 喜歡喜歡
    • 3 頂
    • 1 難過難過
    • 5 囧
    • 3 圍觀圍觀
    • 2 無聊無聊

    熱門評論

    最新評論

    發(fā)表評論 查看所有評論(1)

    昵稱:
    表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
    字?jǐn)?shù): 0/500 (您的評論需要經(jīng)過審核才能顯示)