How can i do that a stored procedure ignore a Error

  • I have a stored procedure using insert statement, this insert can cause a key duplicate error.

    How can i do that this stored procedure ignore this error?

  • Try to avoid the duplicated key.

    insert into table

    select ---- from insertTable

    where not exists(select * from table where key = insertTable.key)

  • To continue processing after an error you must turn off XACT_ABORT then check and respond to (or ignore) the error yourself.

    DECLARE @iErrorID INT

    SET XACT_ABORT OFF

    INSERT INTO TABLE

    SELECT @iErrorID = @@ERROR

    THEN use IF logic to respond to error number according to your desires.

    Additionally, you will still get error raised if you has an invalid column or table name or similar type of error.

    Glenn

     

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply