I have the following cursor (I am using a cursor because I want to use the stored procedure. Inside the stored procedure I have a TRY, and catch statement.If the procedure runs into a certain condition I raise a error using the lineRaiseError('My Error',16,1)For some reason when this happens my cursor gets stuck in a loop because it just keeps trying to processess the same record (Basically when the error occurs the while statment starts over, so there is no fetch next).Is there anyway to fetch next on error, so It doesn't get stuck on the same record?Cursor codeDeclare @GroupID varchar(50),@EmployerID intDeclare CurGroups Cursor for select a.GroupID,a.EmployerID from T_Mytable aopen CurGroups fetch Next from CurGroups into @GroupID ,@EmployerID BEGIN WHILE @@Fetch_Status = 0 exec Sproc_ReGenerateEmployerHourly @GroupID select @GroupID fetch Next from CurGroups into @GroupID ,@EmployerID ENDCLOSE curGroups deallocate curGroups
Stored ProcedureCreate Procedure [dbo].[Sproc_ReGenerateEmployerHourly]@GroupID Varchar(50)asSet NOCOUNT ONBegin Try BEGIN RaiseError('My Error',16,1) ENDEND tryBEGIN CATCH IF (XACT_STATE()) <> 0 ROLLBACK DECLARE @ErrMsg varchar(4000), @ErrSeverity int set @ErrMsg = ERROR_MESSAGE() Set @ErrSeverity = ERROR_SEVERITY() RAISERROR(@ErrMsg, @ErrSeverity, @ErrSeverity) return 0END CATCHhow do I resolve this?