sql server實(shí)現(xiàn)分頁的方法實(shí)例分析
本文實(shí)例講述了sql server實(shí)現(xiàn)分頁的方法。分享給大家供大家參考,具體如下:
declare @index int,@num int
set @index = 1--當(dāng)前頁
set @num = 2--單頁包含的行數(shù)
--分頁1
select top (@num) *
from ppohd
where doccode not in
(
select top (@num * (@index -1)) doccode
from ppohd
order by doccode
)
order by doccode
--分頁2
select top (@num) *
from ppohd
where doccode >=
(
select max(doccode)
from
(
select top (@num * (@index - 1) + 1) doccode
from ppohd
order by doccode
) as tb
)
--分頁3
select top (@num) *
from
(
select ppohd.doccode as 'mydoccode',row_number() over (order by doccode) as sno,*
from ppohd
) as tb
where tb.sno >= @num * (@index - 1) + 1
--分頁4
select *
from
(
select ppohd.doccode as 'mydoccode', row_number() over(order by doccode) as sno,*
from ppohd
) as tb
where tb.sno between (@num * (@index - 1) + 1) and (@num * @index)
更多關(guān)于SQL Server相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《SQL Server分頁技術(shù)總結(jié)》、《SQL Server查詢操作技巧大全》、《SQL Server存儲(chǔ)過程技巧大全》、《SQL Server索引操作技巧大全》、《SQL Server常用函數(shù)匯總》及《SQL Server日期與時(shí)間操作技巧總結(jié)》
希望本文所述對(duì)大家SQL Server數(shù)據(jù)庫程序設(shè)計(jì)有所幫助。
相關(guān)文章
如何在SQLSERVER中快速有條件刪除海量數(shù)據(jù)
如何在SQLSERVER中快速有條件刪除海量數(shù)據(jù)...2006-09-09
SQL server服務(wù)顯示遠(yuǎn)程過程調(diào)用失敗的解決方法
這篇文章主要為大家介紹了SQL server服務(wù)顯示遠(yuǎn)程過程調(diào)用失敗的解決方法,還為大家提供了解決SQL SERVER 2008 R2配置管理器出現(xiàn)“遠(yuǎn)程過程調(diào)用失敗”(0x800706be)錯(cuò)誤提示的方案,感興趣的小伙伴們可以參考一下2016-05-05
sql 存儲(chǔ)過程分頁代碼 支持億萬龐大數(shù)據(jù)量
sql 存儲(chǔ)過程分頁代碼 支持億萬龐大數(shù)據(jù)量,需要的朋友可以參考下。2011-09-09
SQL Server 日期相關(guān)資料詳細(xì)介紹
對(duì)于開發(fā)人員來說,日期處理或許簡單,或許很難。結(jié)合自己過往的開發(fā)經(jīng)驗(yàn)并整合網(wǎng)上的例子,總結(jié)出一些日期相關(guān)的操作,供自己備用及為大家分享2012-06-06
在SQL Server中將數(shù)據(jù)導(dǎo)出為XML和Json的方法
這篇文章主要介紹了在SQL Server中將數(shù)據(jù)導(dǎo)出為XML和Json的方法,需要的朋友可以參考下2015-02-02
在 SQLSERVER 中快速有條件刪除海量數(shù)據(jù)
最近有個(gè)朋友問我,他說他在SQLSERVER刪除幾百萬到幾千萬數(shù)據(jù)是顯的很慢,幫他分析了一下,提了一些以下意見,或許對(duì)很多人有用。2008-10-10

