我可以将存储过程的结果获取到SQL中的另一个存储过程中的游标中 [英] Can I get the results of a stored procedure into a cursor within another stored procedure in SQL

查看:129
本文介绍了我可以将存储过程的结果获取到SQL中的另一个存储过程中的游标中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将一个存储过程的结果放到一个游标中,以便在当前过程中使用。我已经在下面添加了我的代码,但是我不知道这是否可能,或者如果我的语法是正确的?

  DECLARE cursorIDList CURSOR FOR 
EXEC spGetUserIDs
OPEN cursorIDList

FETCH NEXT FROM cursorIDList INTO @ID

我收到以下错误:'EXEC'附近的语法不正确。提前感谢。

解决方案

您可以这样做:

  DECLARE @t TABLE(ID INT)
INSERT INTO @t
EXEC spGetUserIDs

DECLARE cursorIDList CURSOR FOR
SELECT * FROM @t
OPEN cursorIDList

FETCH NEXT FROM cursorIDList INTO @ID


I'm trying to put the results of a stored procedure into a cursor to use within the current procedure. I've added my code below but I'm not sure if this is possible or if my syntax is correct?

DECLARE cursorIDList CURSOR FOR
    EXEC spGetUserIDs
OPEN cursorIDList

FETCH NEXT FROM cursorIDList INTO @ID

I receive the following error: Incorrect syntax near 'EXEC'. Expecting SELECT, '(' or WITH.

Thanks in advance.

解决方案

You can do it like this:

DECLARE @t TABLE (ID INT)
INSERT INTO @t
EXEC spGetUserIDs

DECLARE cursorIDList CURSOR FOR
    SELECT * FROM @t
OPEN cursorIDList

FETCH NEXT FROM cursorIDList INTO @ID

这篇关于我可以将存储过程的结果获取到SQL中的另一个存储过程中的游标中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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