First of all, concerning that you are using SQL Server Destination, i suggest reading the following answer from the SSIS guru @billinkc:
I will provide different methods to achieve that:
(1) Using Lookup transformation
- You should add a Data Flow Task, where you add the second inventory (legacy) as source
- Add a lookup transformation where you select the first inventory source as lookup table.
- Map the source and lookup table with
ItemCode
column
- In the lookup transformation select
Redirect rows to no match output
from the drop down list.
- Use the Lookup no match output to get the desired rows (not found in the first Inventory source)
You can refer to the link below, it contains a step by step tutorials.
Helpful link
Old Versions of SSIS
If you are using old versions of SSIS, then you will not find the Redirect rows to no match output
drop down list. Instead you should go to the Lookup Error output, select Redirect Row
option for No Match
situation, and use the error output to get the desired rows.
(2) Using Linked Servers
On the Second inventory create a Linked server to be able to connect the the first Server. Now you are be able to use an SQL Command that only select the rows not found in the first source:
SELECT *
FROM Inverntory2
WHERE NOT EXISTS (SELECT 1 FROM <Linked Server>.<database>.<schema>.Inverntory1 Inv1 WHERE Inverntory2.ItemCode = Inv1.ItemCode)
(3) Staging table + MERGE, MERGE JOIN , UNION ALL transformation
On each source SQL command add a fixed value column that contains the source id (1,2), example:
SELECT *, 1 as SourceID FROM Inventory
You can combine both sources in one destination using one of the transformation listed above, then add a second Data flow task to import distinct data from staging table into destination based on the ItemCode column, example:
SELECT * FROM (
SELECT *, ROW_NUMBER() OVER(PARTITION BY ItemCode ORDER BY SourceID) rn
FROM StagingTable ) s
Where s.rn = 1
Then it will return all rows from SourceId =1
and the new rows from SourceId = 2
To learn more about Merge, Merge Join and UNION ALL transformation you can refer to one of the following links:
Note: check the answer provided by @userfl89 it contains very detailed information about using Merge Join transformation and it described another approach that can help. Now you have to test which approach fits your needs. Good Luck