PDA

Click to See Complete Forum and Search --> : SQL server stored procedure


msdnexpert
Dec 4th, 2000, 05:54 AM
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

Ianpbaker
Dec 4th, 2000, 06:20 AM
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