?
Solved

skip error on Batch Insert

Posted on 2006-05-10
2
Medium Priority
?
538 Views
Last Modified: 2012-05-05
id like to do a batch insert like:

INSERT INTO TABLE (ID,FID)
SELECT @ID, fID FROM Table

but if it errors on an insert like a unique key violation... i'd like to skip it and do the rest.



any ideas or is there a better way to design this?


0
Comment
Question by:vinny45
2 Comments
 
LVL 39

Accepted Solution

by:
appari earned 2000 total points
ID: 16655281
you can add a where condition to your select statement

suppose your unique key is ID and FID
change your sql to

INSERT INTO TABLE (ID,FID)
SELECT @ID, fID FROM Table T1
where not exists(Select 1 from table T2 where T2.ID = T1.ID and T2.FID = T1.FID)
0
 
LVL 17

Expert Comment

by:HuyBD
ID: 16655326

INSERT INTO TABLE1(ID,FID)
SELECT @ID, fID FROM Table2
where @ID not in (Select ID from table1)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question