Results 1 to 2 of 2

Thread: SQL server stored procedure

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    266
    Here is a sample stored procedure and its testing code.
    When I run the test code for testing the stored procedure I get the following error.
    Cursor with the name ABCD already exists.

    Here is the stored procedure
    CREATE PROCEDURE HELLOTEST
    @IN_VAR NUMERIC
    AS
    DECLARE ABCD CURSOR
    FOR SELECT FIRST FROM TESTTAB
    OPEN ABCD
    WHILE @@FETCH_STATUS = 0
    BEGIN
    --I do something
    END
    GO


    Here is the test code
    DECLARE @TEST_VAR NUMERIC
    SET @TEST_VAR=1
    EXECUTE HELLOTEST @TEST_VAR

    Now when I run the test code I get the error
    Cursor with the name 'ABCD' already exists.
    Any suggestions

  2. #2
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    Hi MSDN. You need to drop the cursor at the end of the sp otherwise sql keeps it like a sp.

    drop your sp then re-create it as the following


    CREATE PROCEDURE HELLOTEST
    @IN_VAR NUMERIC
    AS
    DECLARE ABCD CURSOR
    FOR SELECT FIRST FROM TESTTAB
    OPEN ABCD
    WHILE @@FETCH_STATUS = 0
    BEGIN
    --I do something
    END
    CLOSE ABCD
    DEALLOCATE ABCD
    GO

    that should sort out your problem

    hope it does

    Ian
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width