分页
select * from
(select *, Row_NUMBER() over(order by 列名) as num from 表) as t
where num between 1 and 5
order by time desc
存储过程
create proc usp_GetPage
@pageIndex int, --页码
@pageSize int, --页容量
@pageCount int output --共多少页
as
declare @n int
select @n=COUNT(*) from 表
set @pageCount =ceiling(@n*1.0/@pageSize )
select * from
(select *, ROW_NUMbER() over(order by 列名)as num from 表) as t
where num between(@pageIndex -1)*@pageCount +1 and @pageIndex *@pageSize
order by 列
本文介绍了使用SQL进行数据分页的方法及存储过程的创建方式。通过ROW_NUMBER()函数实现简单分页,并演示了如何利用存储过程来动态调整分页参数,实现更灵活的数据检索。
1325

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



