Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

HOW TO RETURN CURSOR FROM STORE PROCEDURE

Posted on 2002-03-25
1
Medium Priority
?
764 Views
Last Modified: 2008-01-16
I have a stored procedure that I am calling from another stored procedure.  I like to be able to get a cursor back from the called stored procedure so I can loop through it in the calling stored procedure.
0
Comment
Question by:CodeHead
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 200 total points
ID: 6895060
I'm not sure if you can do that directly.  Even cursor variables in SQL 2000 can only be local cursors.  

You could declare a global cursor in the called procedure and then use it in the calling procedure.  That should work just fine.  For example:

--Calling_Procedure
EXEC called_proc
FETCH NEXT FROM csr_global INTO ...
...
CLOSE csr_global
DEALLOCATE csr_global


--Called Procedure
...
DECLARE csr_global CURSOR GLOBAL
FOR ...

But, be SURE that you close and deallocate a global cursor, otherwise it may continue to consume resources even long after you stop using it.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question