In this article we are going to perform Right Outer Join on two SQL tables using Merge Join Transformation in SSIS. Please refer Left Outer Join in SSIS article to understand, How to perform Left Outer Join on two SQL Server Tables and also refer Full Outer Join in SSIS article to understand, How to perform Full Outer Join on two SQL Server Tables using Merge Join Transformation.
Before we start creating the SSIS Package let us look at our two source tables on which we are going to perform Right Outer Join in SSIS using Merge Join Transformation.
Employees Table inside the [SSIS Tutorial] Database is:
Department Table inside the [SSIS Tutorial] Database is:
Configure Right Outer Join in SSIS 2014
STEP 1: Drag and drop the data flow task from the toolbox to the control flow region and rename it as Performing Right Outer Join in SSIS Using Merge Join Transformation
Double click on the data flow task will take us to Data flow region.
STEP 2: Drag and Drop two OLE DB Sources from the toolbox to data flow region and then double-click on first OLE DB source in the data flow region will open the connection manager settings and provides option to select the table holding the source data.
From the above screenshot you can observe that, We selected [Employees] Table from [SSIS Tutorials] Database
STEP 3: Click on columns tab to verify the columns. In this tab we can uncheck the unwanted columns also.
STEP 4: Double click on second OLE DB source to configure the Second table to perform Merge Join. Here we are selecting the [Department] Table from [SSIS Tutorials] Database
STEP 5: Click on columns tab to verify the columns. In this tab we can uncheck the unwanted columns also.
STEP 6: Drag and drop two Sort Transformations from SSIS toolbox to Data Flow region and connect the OLE DB Source output arrow to the Sort Transformation.
STEP 7: Double click on Sort Transformation to configure it. Check the columns we want to sort and don’t forget to Pass Through remaining column. If you forget to select the Pass Through then they won’t appear in output columns.
From the source data, DepartID is the Joining key between Employees and Department tables. So We are sorting the Employees table by DepartID in ascending order.
TIP: Merge Join Transformation will not work without sorting the input rows. So Sort Transformation is mandatory before applying Merge Join Transformation. Please refer Sort Transformation in SSIS article to understand, How to perform Sort Operations on the Source Data.
Double click on Sort Transformation 1 and sort the Department table using id column in ascending order.
STEP 8: Now drag and drop the Merge Join Transformation into data flow region to perform Right Outer Join on the sorted tables.
When you drag the output arrow of the Sort Transformation into Merge Join Transformation an Input Output Selection window will be appeared to select whether it is Merge Join Left Input or Merge Join Right Input as shown in the below screenshot.
Here we selected Merge Join Left Input for Employees table. Click ok and drag and drop the output arrow of the Sort Transformation 1. Here Merge Join Right Input is automatically selected by the intelligence.
STEP 9: Double click on Merge Join Transformation will open the Merge Join Transformation Editor to configure it.
Join Type provides a drop down list to select the Join type (such as Inner Join, Left Outer Join and Full Outer Join) you want to perform on the source data. In this example, Although we are performing Right Outer Join, Merge Join Transformation Editor doesn’t have that option. So for now, We selected the Left Outer Jon option from the Join Type option.
As you can observe from the source data, both Employees and Department tables are joined using DepartID and id columns so select them as Join keys by dragging the arrow.
Now select the columns you want to send to the destination table (Pass through columns) by check marking the column names.
From the above screenshot you can observe that, We selected [First Name], [Last Name] and [Department Name] columns as output columns. To perform Right Outer Join we have to Swap the tables so Click on the Swap Inputs button. By this Left table become Right table and Right table becomes Left table as shown in below screenshot.
It means Right Outer Join will display all the [Department Name] column rows and matching rows of [First Name], [Last Name] columns from the Employees tables where DepartID is exactly equal to any of the id column data. All the non matching rows of the [First Name], [Last Name] columns will be treated as NULL.
TIP: Whatever columns you select here will only be stored in the destination table. If you don’t want any column then uncheck that column.
STEP 10: Drag and drop the OLE DB destination into the data flow region and double-click on it to configure the destination server and destination table to store the Merge Join Transformation output
Here we selected [SSIS Tutorials] as database and [Right Outer Join Using Merge Join Transformation] as destination table
STEP 11: Click on the columns Tab to check whether input columns are matching with the destination columns or not. If not, Please assign the appropriate columns to destination columns
We finished designing the Performing Right Outer Join Using Merge Join Transformation package. Let us execute the SSIS package
Now lets open the SQL Server Management studio and select the columns from [Right Outer Join Using Merge Join Transformation] table.
Thank you Visiting Our Blog