通过存储过程如何返回所需当前页数据
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,@rowcount=@rowcount output
select @rowcount as 总行数,ceiling(1.0*@rowcount/@pagesize) as 页数,@pagecount as 当前页
set @pagecount=(@pagecount-1)*@pagesize+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