Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 cursor error

Author  Topic 

shubhada
Posting Yak Master

117 Posts

Posted - 2007-08-07 : 02:15:05
I have a proc as following

DECLARE @id_temp_tran int,
@num_updated int,
@num_failed int,
@batch_count int,
@id_tran int,
@id_imnt int,
@status int,
@count_imnt int,
@id_typ_tran varchar(20),
@dt_chg_grd datetime,
@id_own_grd int,
@debug smallint,
@id_client varchar(50),
@id_tran_seq int,
@id_typ_event char(7)

SELECT @count_imnt = 0


DECLARE crsr_imnt cursor for
select id_imnt from tempdb..ANVIL_IDS
FOR READ ONLY
go


OPEN crsr_imnt
FETCH crsr_imnt INTO @id_imnt

WHILE @@sqlstatus = 0
BEGIN

EXEC @status = PYR_TRADE..dim_get_tran_id @id_tran = @id_tran OUTPUT

IF @status = 0
BEGIN
EXEC PYR_TRADE..dim_create_event_imnt
@id_tran = @id_tran,
@id_tran_seq = 1,
@id_typ_event = 'INSERT',
@id_imnt = @id_imnt,
@debug = 1


EXEC PYR_TRADE..dim_create_event_transaction
@id_tran = @id_tran,
@id_typ_tran = 'INSTRUMENT',
@debug = 1

INSERT INTO tempdb..ANVIL_TRAN
VALUES(@id_tran)

SELECT @count_imnt = @count_imnt + 1

END

ELSE
BEGIN
print "Failed to get a DIM transaction ID for anvil id_imnt %1!.", @id_imnt
END

FETCH crsr_imnt INTO @id_imnt
END -- While

CLOSE crsr_imnt
DEALLOCATE CURSOR crsr_imnt
go


But at the time of execution ,I am getting the following error
Msg: 7344, Severity 15, Line 19
ErrorMsg: DECLARE CURSOR must be the only statement in a query batch.

Plz tell me how to overcome this problem


SQLTeam

pootle_flump

1064 Posts

Posted - 2007-08-07 : 03:10:07
Remove the GO after READ ONLY.
Go to Top of Page

shubhada
Posting Yak Master

117 Posts

Posted - 2007-08-07 : 03:12:24
tried but still gettiing the same error..

SQLTeam
Go to Top of Page

Jim77
Constraint Violating Yak Guru

440 Posts

Posted - 2007-08-07 : 03:56:40
WHILE @@sqlstatus = 0

should be changed to

WHILE @@FETCH_STATUS <> -1



FETCH crsr_imnt INTO @id_imnt

should be changed to for both occurances.

FETCH NEXT FROM crsr_imnt INTO @id_imnt
Go to Top of Page
   

- Advertisement -