Solved

HOW TO RETURN CURSOR FROM STORE PROCEDURE

Posted on 2002-03-25
1
707 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
1 Comment
 
LVL 69

Accepted Solution

by:
ScottPletcher 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now