declare @index int,@num int
set @index = 1--当前页
set @num = 2--单页包含的行数
--分页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)
sql server 实现分页
最新推荐文章于 2023-03-03 14:23:17 发布