Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cursor issue 1

Status
Not open for further replies.

Newbi1

Programmer
Apr 4, 2005
64
US
I started writing this stored procedure and it keeps claiming:

Server: Msg 16915, Level 16, State 1, Line 23
A cursor with the name 'statcur' already exists.
Server: Msg 16905, Level 16, State 1, Line 25
The cursor is already open.


here is the code as I am not at my best today:

Code:
declare @type char(2)
set @type = 'PL'

--select * from AFinance100
declare @startgl varchar(12),
	@endgl varchar(12),
	@statementAcc varchar(10),
	@curbalance money,
	
	@acctCur cursor


Declare @sheet table
   (Account varchar(10),
        AccountName nvarchar(50),
        Balancecy money,
	Balancepy money,
        totalsto varchar(10))

insert into @sheet select distinct sacc, snam, 0.00,0.00, stot from AFinance100 where ftyp = @type


declare statcur CURSOR FOR  select distinct Account from @sheet

open statcur
fetch next from statcur into @statementAcc


while @@fetch_status = 0 
begin

	select @statementAcc

	fetch next from statcur into @statementAcc
end



select * from @sheet
 
You need to close your cursor at the end of your script:

Code:
CLOSE statcur
DEALLOCATE statcur

You will also need to run this code before trying to run the whole thing again (assuming you have already run the code once during this connection).

--James
 
thanks... It is going into a stored procedure and I spaced where I was in the process
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top