sql server實現(xiàn)分頁的方法實例分析
本文實例講述了sql server實現(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存儲過程技巧大全》、《SQL Server索引操作技巧大全》、《SQL Server常用函數(shù)匯總》及《SQL Server日期與時間操作技巧總結(jié)》
希望本文所述對大家SQL Server數(shù)據(jù)庫程序設(shè)計有所幫助。
相關(guān)文章
輕量級數(shù)據(jù)庫SQL?Server?Express?LocalDb介紹
這篇文章介紹了輕量級數(shù)據(jù)庫SQL?Server?Express?LocalDb,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06
快速插入大量數(shù)據(jù)的asp.net代碼(Sqlserver)
目標(biāo)數(shù)據(jù)庫只能是Sqlserver 來源數(shù)據(jù)庫 無所謂 只要能用ado.net 將來源數(shù)據(jù)讀取到Dataset或者Datareader 中就可以了。2011-02-02
數(shù)據(jù)庫SQL中having和where的用法區(qū)別
這篇文章主要介紹了數(shù)據(jù)庫SQL中having和where的用法區(qū)別的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-11-11
SQLSERVER查看數(shù)據(jù)庫日志方法與語句示例代碼(已親測)
在數(shù)據(jù)庫使用很久后日志文件會累計的越來越大,如果硬盤空間不足可能會導(dǎo)致宕機,下面這篇文章主要給大家介紹了關(guān)于SQLSERVER查看數(shù)據(jù)庫日志方法與語句的相關(guān)資料,需要的朋友可以參考下2023-03-03
SQL Server提示"選定的用戶擁有對象,所以無法除去該用戶”
今天在幫朋友弄一臺服務(wù)器的時候當(dāng)我需要刪除一個數(shù)據(jù)庫里的用戶時,提示如下錯誤信息: "選定的用戶擁有對象,所以無法除去該用戶" 如何解決呢?2009-04-04
sql 版本詳解 讓你認(rèn)識跟sql2000的區(qū)別
如果你是初學(xué)者,如果你只是想要在家里學(xué)習(xí)學(xué)習(xí),如果你的環(huán)境是 WindowsXP Pro,那么,你應(yīng)該選擇的 是 SQL2005 Development(開發(fā)版),而不是 SQL2005 Enterprise (企業(yè)版)或 SQL2005 Express(簡易版)。2010-05-05
SQL Server把某個字段的數(shù)據(jù)用一條語句轉(zhuǎn)換成字符串
這篇文章主要介紹了SQL Server把某個字段的數(shù)據(jù)用一條語句轉(zhuǎn)換成字符串,本文講解使用一條語句把字段中的數(shù)據(jù)查詢出來并以指定分割符組成字符串,需要的朋友可以參考下2015-07-07

