The code below has worked for years on my SQL Server 2000 database. I recently moved the same code to SQL Server 2005 and it worked fine too. But I just installed the DB that contains this procedure on to a new SQL Server 2005 machine and for some reason I am getting the message 'A cursor with the name MyUserCursor does not exist'.
I checked the Database setting for default Cursors and it's set to Global. I also tried to add the word Global after Cursor just to make sure it was not using a Local cursor, but I still get the same message.
I believe the error is occuring because the OPEN MyUserCursor line is not seeing the cursor b/c it's being declared in the EXEC line.
But I emphasize that this code runs perfectly on other servers running both SQL Server 2000 & 2005.
DECLARE @MySQL VarChar(200), @MySQL2 VarChar(200)
Set @MySQL = 'Select Item' + @ItemNumber + ' From [Users] WHERE [User] = ''' + @MyUser + ''''
Set @MySQL2 = 'DECLARE MyUserCursor CURSOR FOR ' + @MySQL
EXEC (@MySQL2)
OPEN MyUserCursor
FETCH NEXT FROM MyUserCursor INTO @MyReturn
DEALLOCATE MyUserCursor
Thanks in advance!!!
I checked the Database setting for default Cursors and it's set to Global. I also tried to add the word Global after Cursor just to make sure it was not using a Local cursor, but I still get the same message.
I believe the error is occuring because the OPEN MyUserCursor line is not seeing the cursor b/c it's being declared in the EXEC line.
But I emphasize that this code runs perfectly on other servers running both SQL Server 2000 & 2005.
DECLARE @MySQL VarChar(200), @MySQL2 VarChar(200)
Set @MySQL = 'Select Item' + @ItemNumber + ' From [Users] WHERE [User] = ''' + @MyUser + ''''
Set @MySQL2 = 'DECLARE MyUserCursor CURSOR FOR ' + @MySQL
EXEC (@MySQL2)
OPEN MyUserCursor
FETCH NEXT FROM MyUserCursor INTO @MyReturn
DEALLOCATE MyUserCursor
Thanks in advance!!!