Solved

HOW TO RETURN CURSOR FROM STORE PROCEDURE

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Select - identify record discrepancies 1 30
Linked Server - SP with Param to VIew 7 21
Need help with a query 14 36
Connect Gridview column to Textbox in C# 2 36
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
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.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

735 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