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.
| 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_CursorThanks 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_listPlease 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 FORSELECT surnameFROM EmployeeWHERE 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 @ReportWHILE (@@FETCH_STATUS <> -1)BEGIN FETCH NEXT from @ReportEND-- Close and deallocate the cursor from sp_cursor_list.CLOSE @ReportDEALLOCATE @ReportGO-- Close and deallocate the original cursor.CLOSE abcDEALLOCATE abcGO 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 |
 |
|
|
|
|
|