1

I have this sql procedure:

create procedure DELETE as
DECLARE VARIABLES
begin TRY
DECLARE CURSOR FOR SELECT ANYTHING
OPEN CURUPD 
FETCH NEXT FROM CURUPD INTO VARIABLES
WHILE @@FETCH_STATUS = 0 BEGIN  
    UPDATE TABLE BASED SON VARIABLES
FETCH NEXT FROM CURUPD INTO VARIABLES
END 
CLOSE CUR
DEALLOCATE CUR
end TRY
begin catch
 DO NOT CARE ABOUT THE ERROR BUT CONTINUE UPDATE ON NEXT RECORD
end catch;

Is this possible? Robert :-)

3 Answers 3

2

You would have to put the TRY/CATCH inside of the WHILE loop. The way you have it, you can't continue the WHILE loop, because it's already finished.

Sign up to request clarification or add additional context in comments.

Comments

1

Try this code:

create procedure DELETE as
DECLARE VARIABLES
begin TRY
DECLARE CURSOR FOR SELECT ANYTHING
OPEN CURUPD 
FETCH NEXT FROM CURUPD INTO VARIABLES
WHILE @@FETCH_STATUS = 0 BEGIN  
    UPDATE TABLE BASED SON VARIABLES
FETCH NEXT FROM CURUPD INTO VARIABLES
END 
CLOSE CUR
DEALLOCATE CUR
end TRY
begin catch
 FETCH NEXT FROM CURUPD INTO VARIABLES
 continue
end catch;

Comments

0

some errors are not trappable and will abort the batch even with try and catch you could check XACT_STATE() and then determine what to do

Why do you need a cursor can't you do a SET based update? Also your try is outside of the loop but you will still have the same problem, try updating an int colum,n with 'A'....BOOM!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.