Before I tried to avoid using cursor because of performance issues. But now I have to do some calculations to reach some goals. I have a stored procedure that has a code like this:
DECLARE Outer_Cursor CURSOR FOR... OPEN Outer_Cursor FETCH NEXT FROM Outer_Cursor INTO ... WHILE @@FETCH_STATUS = 0 BEGIN DECLARE Inner_Cursor CURSOR FOR... OPEN Inner_Cursor FETCH NEXT FROM Inner_Cursor INTO ... WHILE @@FETCH_STATUS = 0 BEGIN ... FETCH NEXT FROM Inner_Cursor INTO ... END CLOSE Inner_Cursor DEALLOCATE Inner_Cursor FETCH NEXT FROM Outer_Cursor INTO ... END CLOSE Outer_Cursor DEALLOCATE Outer_Cursor
Is it possible to avoid (minimize) so expensive cursor recreation for inner cursor. How can I reuse inner cursor declaration, if it is possible?