第一种方式:
用ROW_NUMBER() OVER
例:
select * from
(select *,ROW_NUMBER() over (order by ID) rowindex from TableName) as A
where rowindex > pagesize *(pageIndex -1) and rowindex <= pagesize * pageIndex
第二种方式
例:
create proc assetsRegister_Summary
@PageSize int,
@PageIndex int
as
begin
if(@PageIndex = 1)
begin
select top (@PageSize) *
from TableName
end
else
begin
select top (@PageSize)*
from TableName
where ID>
(
select max(ID) as sqid from (select top (@PageSize *(@PageIndex -1))
ID from TableName order by ID) as sqTemp
)
end
end
执行存储过程:exec assetsRegister_Summary 8,5
本文介绍了两种使用SQL进行分页查询的方法。第一种利用ROW_NUMBER()函数为记录分配唯一编号,通过限制编号范围实现分页;第二种通过存储过程实现分页,采用递归方式根据当前页数和页面大小获取相应数据。
487

被折叠的 条评论
为什么被折叠?



