This code in a store procedure worked for years, now on the OPEN
line I am getting A cursor with the name ... does not exist.
Did something change in sp_executesql
that might have caused this to break?
Is there another way of doing this (the need for dynamic SQL is because the @Types
param is passed in as a pre-formatted string for the IN
clause?)
Select @Query = 'DECLARE cur_person CURSOR FOR
SELECT *
FROM MyTable
WHERE PersonID = @PersonnelID
AND Type in ' + @Types + ' <== formatted list for IN clause
EXEC sp_executesql @Query
OPEN cur_person <== get cursor doesn't exist error