I built a SQL db to store SFDC data = I used the import wizard to load data from the weekly export in SFDC. Some of the larger objects were broken into multiple csv files - being the newbie that I am I ended up with two tables that I need to combine. Is there any way, other than merge, that I can accomplish this? After much research that is the only answer I have found. I was looking for the old school 'append' - any possibility of using such a simple command?
Asked
Active
Viewed 49 times
1 Answers
1
You could use an INSERT statement that selects data from one table and inserts into another table if it doesn't already exist.
Here are two examples, based on the assumption that there is a unique ID field for each row. I'm not sure if one of these performs better than the other.
Using a LEFT OUTER JOIN
to determine if the record already exists in the main table:
INSERT INTO dbo.SFDCData (UniqueID INT, Name VARCHAR(50), OtherColumns VARCHAR(300))
SELECT wt.ID, wt.Name, wt.OtherColumns
FROM dbo.SFDCData_WorkTable1 wt
LEFT OUTER JOIN dbo.SFDCData dest ON dest.ID = wt.ID
WHERE dest.UniqueId IS NULL --true only if name doesn't already exist in dbo.SFDCData
Using a NOT IN
a sub-query to determine if the record already exists in the main table:
INSERT INTO dbo.SFDCData (UniqueID INT, Name VARCHAR(50), OtherColumns VARCHAR(300))
SELECT wt.ID, wt.Name, wt.OtherColumns
FROM dbo.SFDCData_WorkTable1 wt
WHERE wt.UniqueId NOT IN (Select UniqueID from dbo.SFDCData )

Adam Porad
- 14,193
- 3
- 31
- 56
-
Thank you for your response - I ended up using the Import wizard but I will save this answer if to use if I ever have to load two files that may have duplicates. – user5728777 Dec 31 '15 at 16:59