存储过程分页

create procedure queryTabel
(
   @PageIndex int,
   @PageSize int
)
as 
begin
  declare @PageLowerBound int
  declare @PageUpperBound int
  set @PageLowerBound=@PageIndex*@PageSize
  set @PageUpperBound=@PageLowerBound+@PageSize-1
  select * from (select t.*,ROW_NUMBER()Over(order by t.id desc) as rowId from [dbo].[T_UserName] t) t1 where t1.rowId>@PageLowerBound and t1.rowId<=@PageUpperBound
end


exec queryTabel 1,10


简单的说row_number()从1开始,为每一条分组记录返回一个数字,这里的ROW_NUMBER() OVER (ORDER BY xlh DESC) 是先把xlh列降序,再为降序以后的没条xlh记录返回一个序号。 

posted @ 2012-12-19 16:37  王永华  阅读(122)  评论(0编辑  收藏  举报