Recurvice SP and Cursor

  • Hi all

    I have a problem related to Stored procedure. i have actually created a SP which creates a Cursor and recursively calls itself. but when on second call it call itself it says:

    Cursor already exists ....

    is there anyother way so that i can create new cursor with different name on every call.

    Pseduo code

    For 1 to 10

     

  • Problem is global cursors.  Can fix with TSQL cursor declare syntax instead of ANSI-92:

                declare c0 cursor local fast_forward for ...

    Or you can change the DB option CURSOR_DEFAULT value to local to set this for your entire DB, after which you can use the ANSI syntax if you prefer.

                alter database pubs set cursor_default local

  • write down these two statements at the end

     

    close cursorname

    deallocate cursorname

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply