分页存储过程ROW_NUMBER() over(order by pid desc)

分页存储过程 : create proc usp_GetMyPhotos  @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 pid desc) as num from Photos) as t where num between @pageSize*(@pageIndex-1) + 1 and @pageSize*@pageIndex

测试:

declare @n int exec usp_GetMyPhotos 1,3,@n output print @n

你可能感兴趣的:(row_number())