SSQL PROCEDURE

  • How can I handle an error in sql procedure if the data that is being fetched

    by the cursor is being inserted into a table which doesn't allowed duplicates. How can I recover from this error and fetch the next records that the cursor has.

    Thanks in advance

  • This was removed by the editor as SPAM

  • I would check to see if the value has been inserted yet, before you do the insert statement. Something like this:

     
    
    IF NOT EXISTS (SELECT * FROM Table1 WHERE ID = @@ID)
    BEGIN
    INSERT Table1 SELECT @@ID, @@SomeOtherData
    END

    OR

     
    
    INSERT Table1
    SELECT @@ID, @@SomeOtherDate
    WHERE NOT EXISTS (SELECT * FROM Table1 WHERE ID = @@ID)

    -Dan


    -Dan

  • The nice thing about a SQL Server stored proc is that it doesn't bomb off when this type of failure occurs. You can check the @@ERROR value, if it's "no dupes allowed" ignore it and go on.

    Is there something I'm missing here?

Viewing 5 posts - 1 through 4 (of 4 total)

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