Execute SQL Task in SSIS Full Row Set

How to return Full row set (or Complete Table) from the SQL server using the SSIS Execute SQL Task with an example. It will also demonstrate the Result Set option Full Row Set. For this, we are going to use the Employee table present in the SQL Tutorial database

Before we start describing the Execute SQL Task in SSIS Full Row Set, Let me show you the SQL Server Employee Table that we use for this example:

Execute SQL Task in SSIS Full Row Set 1

Execute SQL Task in SSIS Full Row Set

In this example, we will use the SSIS Execute SQL Task full row set option to select the data present in the Employee table and save the returned result set in another table. To do so, Drag and drop the Execute SQL Task from SSIS toolbox to designer space.

Execute SQL Task in SSIS Full Row Set 2

Before we start configuring the Execute SQL Task, let me create variables that are required to hold the return records. And to do so, right-click on the design area will open the context menu. Please select the Variables option.

Execute SQL Task in SSIS Full Row Set 3

As you can see from the below screenshot, we created 8 variables. Here, the ResultSet variable of object type will hold the returned result set, and the remaining seven columns will use in another task.

Execute SQL Task in SSIS Full Row Set 4

Now, Double click on the Execute SQL Task Editor will open the Editor to configure it. Let me select the Connection Type as OLE DB Connection, which is connecting to the SQL Tutorial database. Next, we are using the Direct Input as the SQL statement so, click the … button to write the custom SQL command.

Execute SQL Task in SSIS Full Row Set 5

Please write your custom SQL statement here. As you can from the below screenshot, we are writing a Select statement to select all the records that are present in the Employee table.

-- SSIS Execute SQL Task Full Row Set Example
SELECT [FirstName]
      ,[LastName]
      ,[Education]
      ,[Occupation]
      ,[YearlyIncome]
      ,[Sales]
      ,[HireDate]
  FROM [Employee]
Execute SQL Task in SSIS Full Row Set 6

Please change the SSIS Execute SQL Task ResultSet property value from NONE (default) to the Full result set.

Execute SQL Task in SSIS Full Row Set 7

Next, go to the Result Set tab and click the Add button to assign the variables for the return set.

Execute SQL Task in SSIS Full Row Set 8

As we said before, the select statement will return a complete table. So, we are assigning object variable (ResultSet variable) as the result variable.

Execute SQL Task in SSIS Full Row Set 9

Until now, we successfully configure the execute SQL task. But, we intend to save the result set in the SQL database. To do so, we need a For Each Loop container. So, let me Drag and drop the Foreach Loop Container into the Control Flow region

Execute SQL Task in SSIS Full Row Set 10

Double click on it will open the Foreach Loop Editor to configure it. Please navigate yourself to the Collection tab, and select the Enumerator as the Foreach ADO Enumerator. Next, select the Object variable (ResultSet) as the ADO Object source. We will do one separate article for the Foreach ADO Enumerator so blindly follow the steps.

Execute SQL Task in SSIS Full Row Set 11

Next, we have to map the variables so navigate yourself to Variable Mappings tab.

Execute SQL Task in SSIS Full Row Set 12

Our ResultSet will return seven columns from the Employee table. So, we are assigning the previously created user variables to those seven columns.

Execute SQL Task in SSIS Full Row Set 13

Click OK to close the Foreach Loop container. Next, Drag and Drop the Data Flow task inside the Foreach Loop.

Execute SQL Task in SSIS Full Row Set 14

Double click on the Data Flow Task will open the data flow tab. Drag and drop OLE DB Source, Derived Column Transformation, and OLE DB Destination from the toolbox to data flow region

Execute SQL Task in SSIS Full Row Set 15

Double click on OLE DB source, and connect to the SQL Tutorial database from the SQL Server. Next, we selected the SQL Command as the Data access mode, and write a simple command. This command returns RowNumber as Column, and its value is 1.

Execute SQL Task in SSIS Full Row Set 16

SQL Command that we used in the above screenshot is:

SELECT 1 AS RowNumber

Next, Double click or right-click on the Derived Column Transformation to add new columns based on the variables. First, let me add a new column for the FirstName variable.

As you can from the below screenshot, we are using the Type Cast function DT_STR to convert the variable value to a string type of length 50.

Execute SQL Task in SSIS Full Row Set 17

Please add the new columns for the remaining variables, as well.

Execute SQL Task in SSIS Full Row Set 18

Next, Double click on the OLE DB Destination to save these newly created columns into the SQL Server database.

Execute SQL Task in SSIS Full Row Set 19

For now, we are connecting to the SQL Tutorial database. I forgot to create a table in the SQL Server so, let me click the New button so that the OLE DB Destination editor will automatically create a table for me.

Execute SQL Task in SSIS Full Row Set 20

It is the table that was generated by the Ole DB. Remember, we removed the unwanted RowNumber column from this definition.

Execute SQL Task in SSIS Full Row Set 21

Click on the Mappings tab to check whether the source columns exactly mapped to the destination columns.

Execute SQL Task in SSIS Full Row Set 22

Clicking OK to finish configuring Execute SQL Task in SSIS Full Row Set package. Let us run the package and see whether we transferred the data using Execute SQL Task or not

Execute SQL Task in SSIS Full Row Set 23

Let us open the SQL Server Management Studio Query window to Preview the data.

Execute SQL Task in SSIS Full Row Set 24