Solved

HOW TO RETURN CURSOR FROM STORE PROCEDURE

Posted on 2002-03-25
1
743 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 69

Accepted Solution

by:
Scott Pletcher earned 50 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

731 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