I would pump the contents of the text file into a staging table. Then update
the existing table via an inner join and insert the new rows from the
staging table into the existing table using an outer join.
I.e.:
- Create staging table (SQL task)
- Pump data from text file into staging table
- UPDATE m SET <column 1> = s.<column 1>, <column 2> = s.<column 2> etc
FROM main_table m INNER JOIN staging_table s
ON m.<primary key> = s.<primary key>
- INSERT INTO main_table (<column list>)
SELECT <column list>
FROM staging_table s
LEFT OUTER JOIN main_table m
ON m.<primary key> = s.<primary key>
WHERE m.<primary key> IS NULL
- Drop staging table
--
Jacco Schalkwijk
SQL Server MVP
"A Fu" <AFu (AT) discussions (DOT) microsoft.com> wrote
Quote:
Hello,
I need to use a csv text file to update/add records in db tables. I have
to loop through each row in the text file, use an ID column to search a db
|
table for any existing records, if a record is found, then do an update, if
not, then do an insert.
Quote:
How exactly can I do this with DTS package? Which task(s) should I use?
Any advice is greatly appreciated.
Thanks
A Fu |