Solved

HOW TO RETURN CURSOR FROM STORE PROCEDURE

Posted on 2002-03-25
1
727 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:
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSIS with VPN COnnection 2 76
always on switch back after failover 2 34
SQL Error - Query 6 26
Return 0 on SQL count 24 30
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

773 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