declare @index int,@num int
set @index = 1--當前頁
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é)》