all groups > sql server misc > november 2004 >
You're in the

sql server misc

group:

Access .adp :How to INSERT all but KEY violations


Access .adp :How to INSERT all but KEY violations JimJimJimJim
11/17/2004 5:16:29 PM
sql server misc:
I am trying to append records from one table to another in a db running on
MSDE, knowing fullwell that some of the data in the source will be
duplicates of that in the destination table's pk.
What I would like to happen is to have the stored procedure plunk in all
records that don't violate the constraint
and silently let the duplicate info fall by the wayside. The trouble is SQL
server seems to abort the whole procedure if
even a single record violates the constraint.

In a regular Access mdb, an INSERT statement (append query) would do just
that. Of course it warns you of the violation but a DoCmd.SetWarnings FALSE
takes care of that.

Any ideas as to what I need to do to achieve that same thing?

Re: Access .adp :How to INSERT all but KEY violations David Portas
11/17/2004 11:23:15 PM
For example:

INSERT INTO TargetTable (key_col, col1, col2, ...)
SELECT S.key_col, S.col1, S.col2, ...
FROM SourceTable AS S
LEFT JOIN TargetTable AS T
ON S.key_col = T.key_col
WHERE T.key_col IS NULL

(where key_col is the primary key).

--
David Portas
SQL Server MVP
--

AddThis Social Bookmark Button