幾種常用存儲過程分頁方法 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 ... 臨時表
復(fù)制代碼 代碼如下:
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