分页存储过程 SQL Sever

来源:互联网 发布:mac mini适合什么人 编辑:程序博客网 时间:2024/04/26 06:07
--分页的存储过程
create proc usp_photos
@pageIndex int,--当前页码
@pageSize int,--页容量
@pageCount int output  --共多少页 输出参数
as
declare @count int
select @count=COUNT(*) from Photos
set @pageCount = CEILING( @count*1.0/@pageSize)

select * from
(select *,ROW_NUMBER() over(order by ptime desc) as num from photos) as t
where num between (@pageIndex-1)*@pageSize+1 and @pageIndex*@pageSize order by  ptime desc
原创粉丝点击