读书人

sqlserver中带分页查询的存储过程返回

发布时间: 2012-12-20 09:53:21 作者: rapoo

sqlserver中带分页查询的存储过程返回怎么是三张表,第三个表才是正确的。怎么让它只返回第三张表
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' --此行注释掉
[其他解释]

引用:
EXEC sp_cursoropen @P1 OUTPUT,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output ---修改下存储过程 sp_cursoropen ,把里面的返回结果集注释掉


-- select @rowcount as 'rowCount' --此行注释掉


请问下怎么修改存储过程 sp_cursoropen ,把里面的返回结果集注释掉呢
[其他解释]
sp_cursoropen 代码贴出来看看
[其他解释]
引用:
sp_cursoropen 代码贴出来看看

EXEC sp_cursoropen @P1 OUTPUT,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
[其他解释]
是创建代码 非执行,要修改存储过程啊
[其他解释]
引用:
是创建代码 非执行,要修改存储过程啊

存储过程代码如下:请问该怎么修改呢?
create procedure XiaoZheng
@sqlstr nvarchar(4000), --查询字符串
@currentpage int, --第N页
@pagesize int --每页行数
as
set nocount on
declare @P1 int, --P1是游标的id
@rowcount int
exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
select ceiling(1.0*@rowcount/@pagesize) as 总页数--,@rowcount as 总行数,@currentpage as 当前页
set @currentpage=(@currentpage-1)*@pagesize+1
exec sp_cursorfetch 16,@currentpage,@pagesize
exec sp_cursorclose @P1
set nocount off

[其他解释]
sp_cursoropen 是这个的创建过程 ,要修改它
[其他解释]
引用:
sp_cursoropen 是这个的创建过程 ,要修改它

能不能说下如何修改这个创建过程呀
[其他解释]
里面找找 类似 select seq_id customer_code 这样的语句 注释掉。

[其他解释]
引用:
里面找找 类似 select seq_id customer_code 这样的语句 注释掉。

哥,里面就这几个字,我没找到呢
[其他解释]
什么宝贝存储过程? 还舍不得开源? 自己玩吧
[其他解释]
引用:
什么宝贝存储过程? 还舍不得开源? 自己玩吧

晕死,是你搞错了吧 ?上面就是整个存储过程
[其他解释]
解释下 EXEC sp_cursoropen @P1 OUTPUT,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output 什么意思?

读书人网 >SQL Server

热点推荐