Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Cursor can not be seen in called SP

Author  Topic 

ZenRoe
Starting Member

14 Posts

Posted - 2008-04-15 : 04:29:48
Good day,

I got a main Stored procedure sp_A which calls another stored procedure sp_B. Important fact: Running the called SP sp_B works without problem. As soon as I call sp_B from sp_A I get the following message: "A cursor with the name 'C1' does not exist."
Cursor C1 in sp_B is dynamically built:

SET @sql ='DECLARE C1 CURSOR GLOBAL FOR SELECT ranking FROM OPENROWSET(' +
@apo+@int_provider_name+@apo+ ',' +
@apo+@int_provider_string+@apo + ',' +
@apo+@int_query_string+@apo +
') FOR READ ONLY'

EXEC(@SQL)

Yes, the burden of dynamic SQL. I assume I need to move the other steps (open / fetch etc.)into the same scope. Anybody any idea ?
Thanks: Peter
   

- Advertisement -