快五年了,不知道这个问题有没人会。

zhenghaibingood 2009-04-29 02:42:17
http://topic.csdn.net/t/20040629/23/3132813.html

DECLARE @cursor INT
DECLARE @rowcount INT

EXEC sp_cursoropen @cursor OUTPUT, N'SELECT * FROM customers where cust_id=@id', 2, 8193, @rowcount output, N'@id', @id=10

EXEC sp_cursorclose @cursor

这个@id如何传入?
...全文
263 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhenghaibingood 2009-04-30
  • 打赏
  • 举报
回复
[@scrollopt =] scroll_options OUTPUT
Is the cursor scroll type. scroll_options is int with a default of 1 (keyset-driven), and can be a combination of these values (exactly one of the first 5 must be specified).

Value Description
0x0001 Keyset-driven cursor.
0x0002 Dynamic cursor.
0x0004 Forward-only cursor.
0x0008 Static cursor.
0x0010 Fast forward-only cursor.
0x1000 Parameterized query.

! 0x1000 Parameterized Query !
居然没看到。
pathuang68 2009-04-29
  • 打赏
  • 举报
回复
表扬
lsd123 2009-04-29
  • 打赏
  • 举报
回复
.
等不到来世 2009-04-29
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 happyflystone 的回复:]
引用 17 楼 szx1999 的回复:
引用 9 楼 happyflystone 的回复:
怎么的,准备贿赂我一下?

呵呵,就是楼主自己提供的呀[/Quote]

哪有小财主向乞丐要贿赂的!

看来我还是缺乏钻研精神,向石头学习
usher_gml 2009-04-29
  • 打赏
  • 举报
回复
UP
you_tube 2009-04-29
  • 打赏
  • 举报
回复
学习
-狙击手- 2009-04-29
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 szx1999 的回复:]
引用 9 楼 happyflystone 的回复:
SQL codeDECLARE @cursor INT
DECLARE @rowcount INT

EXEC sp_cursoropen @cursor OUTPUT
, N'SELECT * FROM t2 where a=@id'
, 135170
, 8193
, @rowcount output
,N'@id int'

[/Quote]
怎么的,准备贿赂我一下?

呵呵,就是楼主自己提供的呀
等不到来世 2009-04-29
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 happyflystone 的回复:]
SQL codeDECLARE @cursor INT
DECLARE @rowcount INT

EXEC sp_cursoropen @cursor OUTPUT
, N'SELECT * FROM t2 where a=@id'
, 135170
, 8193
, @rowcount output
,N'@id int'
,@id=8
EXEC sp_cur…
[/Quote]
135170看来是关键,石头不知哪搞来的资料。。。
magicianchar 2009-04-29
  • 打赏
  • 举报
回复
前段时间做了写了几个类似的存储过程
@id可以做为传入值,通过定义一个字符传保存起来
然后把select语句作为字符传保存起来
然后把两个字符传连接起来,就ok了。

详细交流可以msg。
rjfsrb4 2009-04-29
  • 打赏
  • 举报
回复
高手真多
MagicianLiu 2009-04-29
  • 打赏
  • 举报
回复
哦。。以前没发现,浪费分了。。高手解决完了,支持下!
flairsky 2009-04-29
  • 打赏
  • 举报
回复
N'@id'

@id 没有类型么?

加个类型试试
-狙击手- 2009-04-29
  • 打赏
  • 举报
回复
这样也行

DECLARE   @cursor   INT   
DECLARE @rowcount INT

EXEC sp_cursoropen @cursor OUTPUT
, N'SELECT * FROM t2 where a=@id'
, 135170--4098
, 8193
, @rowcount output
,N'@id int'
,@id=2
EXEC sp_cursorfetch @cursor, 2, 0, 3
EXEC sp_cursorclose @cursor

/*
a b
----------- -----------

a b
----------- -----------
2 6


*/
-狙击手- 2009-04-29
  • 打赏
  • 举报
回复
DECLARE   @cursor   INT   
DECLARE @rowcount INT

EXEC sp_cursoropen @cursor OUTPUT
, N'SELECT * FROM t2 where a=@id'
, 4098
, 8193
, @rowcount output
,N'@id int'
,@id=2
EXEC sp_cursorfetch @cursor, 2, 0, 3
EXEC sp_cursorclose @cursor

/*
a b
----------- -----------

a b
----------- -----------
2 6


*/
htl258_Tony 2009-04-29
  • 打赏
  • 举报
回复
学习
-狙击手- 2009-04-29
  • 打赏
  • 举报
回复
DECLARE   @cursor   INT   
DECLARE @rowcount INT

EXEC sp_cursoropen @cursor OUTPUT
, N'SELECT * FROM t2 where a=@id'
, 135170
, 8193
, @rowcount output
,N'@id int'
,@id=8
EXEC sp_cursorclose @cursor


等不到来世 2009-04-29
  • 打赏
  • 举报
回复
显式指定参数,并将@id的定义提前放:
DECLARE   @cursor   INT   
DECLARE @rowcount INT

EXEC sp_cursoropen @cursor=@cursor OUTPUT
,@paramdef=N'@id int'
,@id=10
,@stmt=N'SELECT * FROM ta where id=@id'
,@scrollopt=2
,@ccopt=8193
,@rowcount=@rowcount output
EXEC sp_cursorclose @cursor


不过又报这个错,不知道怎么解决:

/*
消息 16902,级别 16,状态 24,过程 sp_cursoropen,第 1 行
sp_cursoropen: 参数 'scrollopt' 的值无效。
*/

lg3605119 2009-04-29
  • 打赏
  • 举报
回复
up
hehaiyi2008 2009-04-29
  • 打赏
  • 举报
回复
ai_li7758521 2009-04-29
  • 打赏
  • 举报
回复
帮顶
加载更多回复(4)

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧