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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to continue executing a statement when an Error occurs

Status
Not open for further replies.

GJP55

Technical User
Joined
Feb 2, 2003
Messages
220
Location
GB
Is it possible to override an error message in a stored procedure. I have code that performs an update statement. I want the code to continue through to the next record if if fails on the previous record due to a data type error (245).
At the moment, as soon as it hits a record that has the wrong data type, it fails and displays the error halting the stored procedure.


Declare @contact_number int
Declare @title varchar(10)
Declare @forenames varchar(50)
Declare @surname varchar(90)
Declare @ID int

Declare CursorFields cursor for

SELECT contact_number, title, forenames,surname,ID
FROM Members

open CursorFields

fetch next from CursorFields
into @contact_number,@title,@forenames,@surname,@ID

while @@fetch_status = 0
begin
While @@error = 0
Begin
Exec InsertIndividuals @contact_number , @title , @forenames , @surname , @ID
End

If @@Error <> 0
Begin
...Do some code
End

fetch next from CursorFields
into @contact_number,@title,@forenames,@surname,@ID

End

close CursorFields
deallocate CursorFields

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top