ql语句如下:
create PROC cursor_page
@SqlStr NVARCHAR(4000), --查询字符串
@CurrentPage INT, --第N页
@PageSize INT --每页行数
AS
BEGIN
SET NOCOUNT ON
DECLARE @P1 INT, --P1是游标的id
@rowcount int
EXEC sp_cursoropen @P1 OUTPUT,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
select @rowcount as 'rowCount'
--SELECT CEILING(1.0*@rowcount/@pagesize) AS 总页数--,@rowcount as 总行数,@currentpage as 当前页
SET @currentpage=(@currentpage-1)*@pagesize+1
EXEC sp_cursorfetch @P1,16,@currentpage,@pagesize
EXEC sp_cursorclose @P1
SET NOCOUNT OFF
END
执行存储过程结果如下:
seq_id customer_code
-------------------- --------------------
rowCount
-----------
27
seq_id customer_code
-------------------- --------------------
8122309321 002
8122309531 002
8122310071 002
8122310182 002
8122310231 001
8122310251 001
8122310252 001
8122311361 123
8122311372 123
8122311383 123
8122515251 002
8122515451 001
8122515511 NULL
8122515522 NULL
8122516211 NULL
8122516212 NULL
8122516313 NULL
8122516314 NULL
8122516315 NULL
8122516326 NULL
------最佳解决方案--------------------
EXEC sp_cursoropen @P1 OUTPUT,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output ---修改下存储过程 sp_cursoropen ,把里面的返回结果集注释掉
-- select @rowcount as 'rowCount' --此行注释掉
------其他解决方案--------------------