November 13, 2002 at 12:25 pm
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
November 18, 2002 at 8:00 am
This was removed by the editor as SPAM
November 18, 2002 at 10:04 am
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
December 3, 2002 at 8:38 pm
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?
December 7, 2002 at 9:58 pm
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply