all groups > sql server new users > february 2006 >
You're in the

sql server new users

group:

is there an on key error continue???


is there an on key error continue??? Beemer Biker
2/21/2006 5:18:31 PM
sql server new users:
We have a stored procedure that copies records from one day to another day.
There is a key rule to prevent duplicate records.

The operator might select one record, then another, then decide he really
wanted all of them to be copied. Is there a way to write my stored
procedure so that the duplicate key error is ignored (in the
....select-insert...) and at least all the valid records are copied?

Maybe it is supposed to be doing this already and I got something else
wrong???


--
=======================================================================
Beemer Biker joestateson@grandecom.net
http://TipsForTheComputingImpaired.com
http://ResearchRiders.org Ask about my 99'R1100RT
=======================================================================

Re: is there an on key error continue??? Andrew J. Kelly
2/21/2006 7:20:48 PM
Its pretty tough to say without seeing exactly what you are doing in the sp.
But you can certainly prequalify any rows with an EXISTS statement and just
not insert the ones that will be duplicates. Again without seeing what you
have this is a guess but you can try something like this:

INSERT INTO Table2 (Col1...)
SELECT Col1... FROM Table1
WHERE NOT Exists (SELECT * FROM Table1.Key = Table2.Key)


--
Andrew J. Kelly SQL MVP


[quoted text, click to view]

Re: is there an on key error continue??? Beemer Biker
2/23/2006 8:16:19 AM
[quoted text, click to view]

Thanks Andrew, but after looking at the problem I realized it was not a
duplicate key error, but a rules violation. There are about 10 fields in
the record that have to be unique (all of them) and that was where the
problem was. The key was a guid which is unique, but we made a change to
the rules. I assume that same example you gave should work, but I would
have to add the 10 fields in the test for equality???


--
=======================================================================
Beemer Biker joestateson@grandecom.net
http://TipsForTheComputingImpaired.com
http://ResearchRiders.org Ask about my 99'R1100RT
=======================================================================

Re: is there an on key error continue??? Andrew J. Kelly
2/23/2006 12:15:12 PM
Pretty much Yes. That is a lot of columns to all be unique.

--
Andrew J. Kelly SQL MVP


[quoted text, click to view]

AddThis Social Bookmark Button