Merge Join Transformation in SSIS

The Merge Join Transformation in SSIS performs SQL Joins such as Inner, Left Outer, Full Outer, and Right Outer (indirectly achieved by Swapping the tables) in Integration Services. The SSIS Merge Join Transformation is very useful for loading data into the Dimension tables in Data Warehouse.

NOTE: The Merge Join Transformation in SSIS will only work with Sorted data. So, Sort Transformation is mandatory before applying this. Please refer to the Sorting article to understand, How to perform Sort Operations on the Source Data.

Merge Join Transformation in SSIS Example

In this article, we will perform Inner Join on two SQL tables using Merge Join Transformation in SSIS. Before we start creating the Package, let us look at our two source tables on which we will perform Inner Join.

Employees Table inside the Database is:

Left Table 1

Department Table inside the Database is:

Right Table

STEP 1: Drag and drop the data flow task from the toolbox to the control flow region and rename it as Performing Inner using Merge Join Transformation.

Inner Join Using Merge Join Transformation in SSIS 1

Double click on the SSIS Merge Join Transformation data flow task will take us to the Data flow region.

STEP 2: Drag and Drop two OLE DB Sources from the toolbox to the data flow region. Then double-click on the first OLE DB source in the data flow region will open the connection manager settings and provides an option to select the table holding the source data.

Select Database and Table 3

From the above screenshot, we selected the [Employees] Table from the Database.

STEP 3: Click on the columns tab to verify the columns. In this tab, we can uncheck the unwanted columns.

Check the Available Columns 4

STEP 4: Double click on the second OLE DB source to configure the Second table to perform SSIS Inner Join using Merge transformation. Here we are selecting the [Department] Table from the Database

Preview Query Result 5

STEP 5: repeat step 3

OLE DB Source Editor 6

Sort Transformation

STEP 6: Drag and drop two Sort Transformations from the toolbox to the Data Flow region and connect the OLE DB Source output arrow to the Sort Transformation. We need this to perform before the SSIS merge join transformation.

Merge Join Transformation in SSIS 7

STEP 7: Double click on Sort Transformation to configure it. Check the columns we want to sort, and don’t forget to Pass Through the remaining column. If you fail to select the Pass Through, they won’t appear in the 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.

Merge Join Transformation in SSIS 8

Double click on Sort Transformation1 and sort the Department table using the id column in ascending order.

Merge Join Transformation in SSIS Inner 9

SSIS Merge Join Transformation Configuration

STEP 8: Now drag and drop the Merge Join Transformation into the data flow region to perform Inner on the sorted tables.

When you drag the output arrow of the Sort Transformation into Merge Join Transformation, an Input Output Selection window will appear to select whether it is Merge Left Input or Right Input, as shown in the below screenshot.

Inner using Merge Join Transformation in SSIS 10

Here we selected Merge Join Left Input for the Employees table. Click ok and drag and drop the output arrow of the Sort Transformation 1. Here, the Right Input will automatically select by the intelligence.

STEP 9: Double click on Merge Join Transformation will open the Editor to configure it.

Join Type provides a drop-down list to select the type (such as Inner, Left Outer, and Full Outer) you want to perform on the source data. In this example, we were performing the Inner Join. So that’s why we selected the Inner from the Join Type option.

Inner Join Using Merge Join Transformation in SSIS 11

As you can observe from the source data, both Employees and Department tables joined using DepartID and id columns. So select them as keys by dragging the arrow.

Now choose the columns to send to the destination table (Pass through columns) by check-marking the column names.

Inner Join Using Merge Join Transformation in SSIS 12

From the above screenshot, you can observe that, We selected [First Name], [Last Name], and [Department Name] columns as output columns. It means SSIS Inner Join will produce output columns as [First Name], [Last Name], and [Department Name], where DepartID is precisely equal to any of the id column data.

TIP: Whatever columns you select here will only transfer to the destination table. So if you don’t want any column, uncheck that column.

STEP 10: Drag and drop the OLE DB destination into the data flow region. Next, double-click on it to configure the destination server and table to store the output.

Choose Destination Table

Here we selected the Database and [Inner Join Using Merge Join Transformation] as the destination table

STEP 11: Click on the columns Tab to check whether the input columns match with the destination columns or not. If not, Please assign the appropriate columns to the destination columns.

Mapping Inout and Destination Columns 12

We finished designing the Performing Inner using Merge Join Transformation in the SSIS package. Next, let us execute the package.

Inner Join Using Merge Join Transformation in SSIS 13

Now let’s open the Management Studio and select the columns from Inner using Merge Join Transformation in the table.

Destination Table Output

Comments are closed.