u can write the CLOSE, DEALLOCATE stmts in Catch block also, check thisBEGIN TRY DECLARE Cur CURSOR FAST_FORWARD FOR SELECT DISTINCT ID FROM Staff OPEN Cur FETCH NEXT FROM Cur INTO @Id WHILE (@@FETCH_STATUS = 0) BEGIN -- processing.. print 'LOOP' SELECT @ID * 'A' FETCH NEXT FROM Cur INTO @Id END SELECT Cursor_Status('global', 'Cur') AS 'Cur1' CLOSE Cur DEALLOCATE CurEND TRYBEGIN CATCH SELECT Cursor_Status('global', 'Cur') AS 'Cur2' CLOSE Cur DEALLOCATE Cur PRINT ERROR_MESSAGE() SELECT Cursor_Status('global', 'Cur') AS 'Cur2'END CATCH
If any error occurs then CURSOR is closed in Catch block."There is only one difference between a dream and an aim.A dream requires soundless sleep to see,whereas an aim requires sleepless efforts to achieve..!!"