OLE DB Command Transformation in SSIS

OLE DB Command Transformation in SSIS is used to run the SQL statements like INSERTUPDATE, and DELETE statements in the Data Flow. Please refer to Delete Data Using OLEDB Command Transformation article to understand how to delete data using SSIS OLE DB Command Transformation and Update Data using OLEDB Command Transformationarticle to understand the Update operations.

NOTE: SSIS OLE DB Command Transformation reads one row at a time and applies the SQL statement on that row. So, the performance will be miserable if the number of rows increases. For example, to Update 5 records, OLE DB Command Transformation will run five times.

Insert Data Using OLE DB Command Transformation in SSIS Example

In this example, we will show you how to insert data into the destination table using the OLE DB Command Transformation. Before we start designing the SSIS Package, let us see the Destination Table in [SSIS Tutorials] Database

Inserting Data Using OLE DB Command Transformation in SSIS 0

Drag and drop the Data Flow Task from the toolbox to the control flow region. And rename it as Inserting Data using OLE DB Command Transformation in SSIS.

Inserting Data Using OLE DB Command Transformation in SSIS 1

Double click on it, and it will open the data flow tab.

Drag and drop OLE DB Source and OLE DB Command transformation from the toolbox to the data flow region.

Inserting Data Using OLE DB Command Transformation in SSIS 2

Within the data flow region, Double click on OLE DB source will open the connection manager settings and allows us to select the required table.

Inserting Data Using OLE DB Command Transformation in SSIS 3

The SQL Command we used in the above screenshot is

SELECT [ProductKey]
      ,[EnglishProductName]
      ,[StandardCost]
      ,[Color]
      ,[ListPrice]
      ,[DealerPrice]
      ,[EnglishDescription]

FROM [AdventureWorksDW2014].[dbo].[DimProducts]

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

Inserting Data Using OLE DB Command Transformation in SSIS 4

Drag the OLE DB Source Output arrow on to the OLE DB Command Transformation to perform transformations on the source data.

STEP 5: Double click on the OLE DB Command Transformation will open the Advanced Editor for OLE DB Command to configure it.

Within the Connection Managers tab, we are selecting the already created OLE DB Connection from the list. Please refer to the OLE DB Connection Manager in SSIS article to understand the configuration settings.

Inserting Data Using OLE DB Command Transformation in SSIS 5

Within the Component Properties, we have to write the SQL Statement we have to perform. Please select the SqlCommand property and click on the browse button (… button)

Inserting Data Using OLE DB Command Transformation in SSIS 6

Once you click on the browse button, a String Value Editor window opened to write the SQL Statement. In this example, we are inserting the values into the products table.

Inserting Data Using OLE DB Command Transformation in SSIS 7

SQL Statement we used in for this Ole DB Command Transformation in SSIS is

INSERT INTO [SSIS Tutorials].[dbo].[Products]
           ([EnglishProductName]
           ,[StandardCost]
           ,[Color]
           ,[ListPrice]
           ,[DealerPrice]
           ,[EnglishDescription])
     VALUES
           (?, ?, ?, ?, ?, ?)

Within the Column Mapping, we have to assign the appropriate column name to the parameters.

Inserting Data Using OLE DB Command Transformation in SSIS 8

From the above screenshot, you can observe that Param_0 represents the first question mark, and param_5 represents the fifth question mark.

Let’s assign the appropriate column names to the parameters.

Inserting Data Using OLE DB Command Transformation in SSIS 9

Click OK to finish configuring the Inserting Data Using OLE DB Command Transformation in the SSIS package. Let us Run the package

Inserting Data Using OLE DB Command Transformation in SSIS 10

Let us open the SQL Server Management Studio and check the result

Inserting Data Using OLE DB Command Transformation in SSIS 11