几种常用存储过程分页方法 TopN方法 select Top(@PageSize) from TableName where ID Not IN (Select Top ((@PageIndex-1)*@PageSize) ID from Table Name where .... order by ... ) where .... order by ... 临时表
复制代码 代码如下:
declare @indextable table(id int identity(1,1),nid int,PostUserName nvarchar(50)) declare @PageLowerBound int declare @PageUpperBound int set @PageLowerBound=(@pageindex-1)*@pagesize--下限 set @PageUpperBound=@PageLowerBound+@pagesize--上限 set rowcount @PageUpperBound insert into @indextable(nid,PostUserName) select ReplyID,PostUserName from TableName order by ...... select * from TableName p,@indextable t where p.ID=t.nid and t.id>@PageLowerBound and t.id=@PageUpperBound order by t.id