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 2005 Forums
 Transact-SQL (2005)
 How can I Check the Existence of a Cusor

Author  Topic 

khufiamalik
Posting Yak Master

120 Posts

Posted - 2008-10-23 : 04:13:53
Hello All,

I want to Drop a Cursor.

Can any one tell me that how can I check that a Cursor exists or not.

please provide me a compete syntax.

My Cursor Name is Employee_Cursor

Thanks in Advance

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-10-23 : 05:12:36
Hi khufiamalik,

I've lost track of the number of times that you've asked this question.

I will answer again:

sp_cursor_list

Please look this up in books online / your sql server documentation. Here is a little example script from the books online.



-- Declare and open a keyset-driven cursor.
DECLARE abc CURSOR KEYSET FOR
SELECT surname
FROM Employee
WHERE surname LIKE 'S%'
OPEN abc

-- Declare a cursor variable to hold the cursor output variable
-- from sp_cursor_list.
DECLARE @Report CURSOR

-- Execute sp_cursor_list into the cursor variable.
EXEC master.dbo.sp_cursor_list @cursor_return = @Report OUTPUT,
@cursor_scope = 2

-- Fetch all the rows from the sp_cursor_list output cursor.
FETCH NEXT from @Report
WHILE (@@FETCH_STATUS <> -1)
BEGIN
FETCH NEXT from @Report
END

-- Close and deallocate the cursor from sp_cursor_list.
CLOSE @Report
DEALLOCATE @Report
GO

-- Close and deallocate the original cursor.
CLOSE abc
DEALLOCATE abc
GO


Please look at the code, You can run it in a query analyser window and see how it works. I'll leave it up to you to work out what to do with the information returned.

This won't drop the cursor's found for you. I'm not going to tell you how to do that until you post a suggestion yourself.

-------------
Charlie
Go to Top of Page
   

- Advertisement -