Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jamiesw
Starting Member
6 Posts |
Posted - 2014-06-30 : 11:18:23
|
Hi there, I have a table(MyTable)that also has an unique index that contains 3 fields in the index.something like:ID(PK)|FName|LName|DOB|PostCodeLname, Dob & Postcode are all part of the unique index.I also have a table variable in my stored proc that has the same fields plus a few more.I am trying to do an insert from my @tablevariable into my table.Insert INTO MyTable(Values)Select Values from @tablevariableI get the "Cannot insert duplicate key row in object" error,I need the insert to continue with inserting the rest of the records that don't match regardless.Or be able to delete matching values that already exist from @tablevariablelike loop through the table and delete if found from @tablevariblenot sure if explaining my self properly, ThanksJamie |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-06-30 : 12:43:56
|
Insert INTO MyTable(Values)Select Values from @tablevariable tv where not exists (select * from MyTable mt where tv.Lname = mt.Lname and tv.Dob = mt.Dob and tv.Postcode = mt.Postcode)Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
jamiesw
Starting Member
6 Posts |
Posted - 2014-06-30 : 13:39:28
|
Thanks exactly what I was looking for. My head went blank and was staring at it for ages.Thanks Again |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|