http://topic.csdn.net/t/20040629/23/3132813.htmlDECLARE @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如何传入?
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如何传入?
解决方案 »
- MSSQL 2005 和 2008 的工作群版(Workgroup Edition)具体应用在什么方面?
- sqlserver2005 如何查看select一条语句 所消耗的时间
- sql server 2008与excel之间导入导出数据问题!
- 求sql查询语句。高手请进
- 怎么返回sql-server服务器名?还有..
- 怎样判断字符串中的数字个数字个数或者空格个数
- SQL2000下访问速度特慢!
- 如何在SQL SERVER中定期创建一个库?(用SQL语句实现,或存储过程),非常感谢!!!
- win764位,安装2008遇到这么变态的问题,搞了几天没搞定。
- jsp页面向数据库增加数据和修改数据都会应为乱码而失败
- sql批量更新语句
- 邹老大的书提出的问题:什么时候应该使用存储过程?什么时候使用用户自定义函数?
必须声明变量 '@id'。
服务器: 消息 16945,级别 16,状态 1,过程 sp_cursoropen,行 5
游标未声明。
服务器: 消息 16909,级别 16,状态 1,过程 sp_cursorclose,行 7
sp_cursorclose: 所提供的游标标识符值(0)无效。
就是这种语句:USE pubs-- Create a dynamc read-only cursor
DECLARE @cursor INTEXEC sp_cursoropen @cursor OUTPUT, N'SELECT * FROM myTable WHERE col1=@P1 AND col2 LIKE @P2', 2, 8193, N'@P1 INT, @P2 VARCHAR(255)', 10, '%x%' -- Close the cursor
EXEC sp_cursorclose @cursor
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' 的值无效。
*/
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
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
*/
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
*/
@id可以做为传入值,通过定义一个字符传保存起来
然后把select语句作为字符传保存起来
然后把两个字符传连接起来,就ok了。详细交流可以msg。
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 !
居然没看到。