Friday, February 24, 2012

Local Cursor question... please help...

ANy idea what I missed?
I am getting this error Server: Msg 16916, Level 16, State 1, Procedure IMPGrpEscalationX, Line 28
A cursor with the name 'crImgGrp' does not exist.

Thank you.

*************

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

ALTER PROCEDURE IMPGrpEscalationX

AS

Declare @.IMID int
Declare @.FS1 int
Declare @.FS2 int

Declare crReqRec cursor local for
select IMID from ImplementationGroup where IMStatus= 'Y'
open crReqRec
fetch next from crReqRec
into @.IMID
Set @.FS1 = @.@.fetch_status

Begin
Set @.IMID = (select IMID from Employees_ImplementationGroup where IMID = @.IMID)

Declare crImpGrp cursor local for
select IMID from Employees_ImplementationGroup where IMID = @.IMID

open crImpGrp

fetch next from crImgGrp
into @.IMID
Set @.FS2 = @.@.Fetch_Status
begin
Print 'test'
End

while @.FS2 = 0

fetch next from crImpGrp into
@.IMID
end
while @.FS1 = 0
fetch next from crReqRec into @.IMID

close crImpGrp
deallocate crImpGrp

FETCH next from crReqRec
into
@.IMID

close crReqRec
deallocate crReqRec

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GOlooks like your cursor is going out of scope when you fetch the second time.|||how can I fixed the out of scope?

No comments:

Post a Comment