将游标设置为sql2008中的存储过程以进行循环 [英] set cursor to a stored procedure in sql2008 for loop through

查看:70
本文介绍了将游标设置为sql2008中的存储过程以进行循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将存储过程的返回记录集放入游标中.
我已经动态创建了一个由EXEC sp_executeSQL执行的sql语句,但是我希望将结果放入光标中,以便我可以滚动它们.
可以将结果插入到临时表中,但是能够将它们放在游标中可以为我节省一些工作.

Is it possible to put the returned record set of a stored procedure into a cursor.
I have dynamically created a sql statement which is being executed by the EXEC sp_executeSQL, but I wish to put the results into a cursor so that I can scroll through them.
It is possible to insert the results into a temporary table, but being able to put them in a cursor would save me some work.

推荐答案

创建临时表(创建) TABLE #cursname ...)或游标(DECLARE @cursname CURSOR for ...)

然后使用类似
的东西
Create a temp table (CREATE TABLE #cursname...) or cursor (DECLARE @cursname CURSOR for...)

Then use something like
INSERT INTO #cursname 
EXEC sp_executeSQL



[edit]
刚意识到我混合了临时表和游标.
[/edit]



[edit]
Just realized I mixed temp table and cursor.
[/edit]


这篇关于将游标设置为sql2008中的存储过程以进行循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆