Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Closing Cursor using sp_cursor_list

Author  Topic 

azamsharp
Posting Yak Master

201 Posts

Posted - 2005-09-30 : 00:34:21


In the T-SQL below how can I get the cursor and close it in the query rather than closing the cursor one by one.

DECLARE @Report cursor

EXEC sp_cursor_list @cursor_return = @Report OUTPUT, @cursor_scope=3

FETCH NEXT from @Report
WHILE (@@FETCH_STATUS <> -1)
BEGIN
FETCH NEXT from @Report -- How can I get the cursor that is opened and close it :)
CLOSE @Report
DEALLOCATE @Report
END





Mohammad Azam
www.azamsharp.net

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2005-09-30 : 08:50:40
Stay away from cursors...
try to show us, using sample input data and matching expected results and an english description of the overall problem...and we'll endeavour to get you a 'better (non-cursor)' solution.

You're hitting phase 1 of many problems that are out there to be hit using cursors.
Go to Top of Page

azamsharp
Posting Yak Master

201 Posts

Posted - 2005-09-30 : 17:04:19
Thansk for the reply. What are the disadvantages of using cursors and when it is a good time and scenario to use a cursor?

Thanks again Sir,

Mohammad Azam
www.azamsharp.net
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2005-10-03 : 07:37:36
disadvantages....search here for previous topics!.......but in short....cr*p performance!
when is good time to use one (rarely)....but particularly when you have to perform row-by-row operations....ie where what is on one row affects what you want to see on a succeeding row...(running totals would come to mind)
Go to Top of Page
   

- Advertisement -