当前位置: 代码迷 >> Sql Server >> 通过存储过程怎么返回所需当前页数据
  详细解决方案

通过存储过程怎么返回所需当前页数据

热度:295   发布时间:2016-04-27 21:57:07.0
通过存储过程如何返回所需当前页数据
ALTER   PROCEDURE   dbo.Paging

@sqlstr   nvarchar(4000),   --查询字符串  
@pagecount   int,   --第N页  
@pagesize   int   --每页行数  
AS
BEGIN
    set   nocount   on  
    declare   @P1   int,  
    @rowcount   int  
    exec   sp_cursoropen   @P1   output,@sqlstr,@scrollopt=1,@ccopt=1,@[email protected]   output  
    select   @rowcount   as   总行数,ceiling([email protected][email protected])   as   页数,@pagecount   as   当前页  
    set   @pagecount=(@pagecount-1)[email protected]+1  
    exec   sp_cursorfetch   @P1,16,@pagecount,@pagesize  
    exec   sp_cursorclose   @P1  
end


@sqlstr   =select   *   from   table   order   by   name
@pagecount   =3
@pagesize   =20

返回结果:
总行数                   页数                               当前页                  
-----------   ----------------   -----------  
45508               2276                           3  
我想返回当前第3页的数据,如何操作啊

------解决方案--------------------
select top 20 *
from (select top 60 * from table order by name) t
order by name desc
  相关解决方案