|
Trudye
Posting Yak Master
169 Posts |
Posted - 2008-02-26 : 09:01:58
|
| I am still having problems with my cursors. I am receiving the following errors when I execute my Stored Procedure: Msg 16915, Level 16, State 1, Procedure BatchNonMons2, Line 27A cursor with the name 'MyCursor' already exists.Msg 16905, Level 16, State 1, Procedure BatchNonMons2, Line 31The cursor is already open.Msg 16915, Level 16, State 1, Procedure BatchNonMons2, Line 37A cursor with the name 'vwCursor' already exists.Msg 16905, Level 16, State 1, Procedure BatchNonMons2, Line 38The cursor is already open.Here is the code causing the problem:CREATE PROCEDURE [dbo].[BatchNonMons2] ASBEGIN /* Create a new hdr each time the Sys/Prin changes in the Dtl rec *//* Define every field you want to output */DECLARE @Batch_Type intDECLARE @Batch_Num intDECLARE @Sys varchar (4)DECLARE @Prin varchar (4)DECLARE @Account_Num varchar(16)DECLARE @Tran_Code varchar(3)DECLARE @Clerk_Code varchar(3)DECLARE @Memo_Text varchar(57)DECLARE @SubTrans varchar(2)DECLARE @SubTrans_2 varchar(1)DECLARE @Terminal_Id varchar(3)DECLARE @Op_Code varchar(2)DECLARE @Last4 varchar(6)DECLARE @vwSys varchar (4)DECLARE @vwPrin varchar (4)/* Define Cursor */DECLARE MyCursor cursorFor SELECT Batch_Type, Batch_Number, Sys, Prin, Account_Number, Transaction_Code, Clerk_Code, Memo_Text, SubTrans, SubTrans2, Term_id, Op_Code FROM dbo.tblNonMon_Daily_TransOpen MyCursor; /*Works like an ARRAY*//*holds current record */FETCH NEXT FROM MyCursor INTO @Batch_Type, @Batch_Num, @Sys, @Prin, @Account_Num, @Tran_Code, @Clerk_Code, @Memo_Text, @SubTrans, @SubTrans_2, @Terminal_Id, @Op_CodeDeclare vwCursor cursorFOR SELECT Sys, Prin FROM dbo.vwNonMonSysPrinsopen vwCursor;FETCH next FROM vwcursor INTO @vwSys, @vwPrin /* When @@Fetch_Status = 1 EOF has been reached */WHILE @@Fetch_Status = 0 BEGIN WHILE @vwSys = @Sys BEGIN Any input would be appreciated.Thanx, |
|
|
Trudye
Posting Yak Master
169 Posts |
Posted - 2008-02-26 : 09:56:25
|
| Thank you so much for responding so quickly harsh. You are correct oh wise one. I had the code to cose and deallocate at the bottom of my stored procedure. Obviously it never executed, I'll have to find out why. But you got it right on the button.Thank you again, |
 |
|