Capture and Work with Output Parameters from SQL Stored Procedures using KingswaySoft

17 April 2025
KingswaySoft Team

In SQL-based languages for RDBMS, Stored Procedures are pivotal when it comes to streamlining your process. They are routines that contain one or more SQL statements that can execute a set of database operation tasks to achieve certain goals. An important aspect of SQL Stored Procedures is, that they have the option to support both input and output parameters, which makes them extremely powerful and flexible. When Output (OUTPUT) Parameters are used, it can return values to the caller which might contain the execution results that might be useful for subsequent tasks or queries. Such capabilities can be very useful in an ETL process. For instance, you may call a Stored Procedure that does a number of things, and at the end of the execution, it returns some results that might be needed in subsequent SSIS data flow or control flow tasks. In order to achieve so, the ETL components or tasks have to be able to work with such input and output parameters in order to fully leverage the benefits. Before we move further, we would like to quickly highlight some of the general benefits when using Stored Procedures.

  • Optimized performance, especially in cases with complex SQL queries.
  • Code reusability, due to the modular nature of coding, which can be reused multiple times.
  • Security, by providing permissions to call procedures, and not to the underlying tables.
  • Code readability, once again, due to its modular and abstract nature.

With our most recent 2025 release wave 1, we have specifically introduced the newly added Output Parameter support in various db-related components so that you can efficiently work with those Stored Procedures when Output Parameters are involved.

Once you have updated your SSIS Productivity Pack installation to the latest v25.1 release, you can start to enjoy the newly added flexibility by calling your SQL stored procedures while having access to those output parameters after execution. For further details of this release, you are welcome to check out our change log page.

In this blog post, however, we shall look specifically at our Premium SQL Server components while working with SQL Stored Procedures, and how they can manage it. We will show you how it works with the same Stored Procedure being run by both our SQL Server Command Task, as well as by our SQL Server Destination component, and see how the Output Parameters can be handled in both Control Flow as well as in a Data Flow. For demonstration, we use the following components: 

Now let's dig in.

Option 1: Using the Premium SQL Server Command Task

The Premium SQL Server Command Task is a control flow task that can be used to execute an SQL command to perform desired db operations. In our example, let's assume that you are getting input values assigned to variables in a previous task or flow, and you would simply wish to pass it to a query or a Stored Procedure and get the output based on that. In this case, rather than have a design-heavy Data Flow, you could use the SQL Server Command Task as a standalone task to capture and use these variables. Let's take a Stored Procedure as an example, where a query is performed, based on the input parameters @FirstName and @LastName, and there are four Output Parameters being defined in it, namely, @Id, @EmailAddress, @Dept, and @Location.

CREATE PROCEDURE GetEmployeeInfo
(
    @FirstName NVARCHAR(10),
    @LastName NVARCHAR(10),
    @Id INT OUTPUT,
    @EmailAddress NVARCHAR(20) OUTPUT,
    @Dept NVARCHAR(10) OUTPUT,
    @Location NVARCHAR(10) OUTPUT
)
AS
BEGIN
    SELECT @Id = id,
           @EmailAddress = email,
           @Dept = DEPT,
           @Location = WORK_LOC
    FROM employee
    WHERE firstname = @FirstName
          and lastname = @LastName;
END;

Now, in our SQL Server Command Task, let's call and execute this Procedure. While doing so, let's map/assign the Input Parameters as the variables. The grid on the left side can be used to drag and drop the desired variables into the command window to parameterize it.

SQL Server command task.png

Once done, now it's time to define how those Output Parameters are received after execution. Navigate to the Output page in the Task, and in the grid "Parameter Output", add the defined parameter name from the Stored Procedure, and choose the respective output variable that should hold the value. Click on the green "+" sign to add new lines and add all the Output Parameters.

SQL Server command task - Output.png

Now, you can reference the output variables in any succeeding design. In our examples, we are simply using a data flow design with a Premium Derived Column that captures these variables and assigns them to a column for us to read at runtime, using a data viewer.

Premium Derived Column component.png

Command Task Flow.png

Please note that the above is just an example to showcase that the Stored Procedure has been executed and the Output Parameters are handled, and you could have these variables used in any design of your choice that suits your requirement. Next, let's look at how the same can be implemented within a Data Flow design.

Option 2: Using the Premium SQL Server Destination component 

Here, say that our requirement is to pass a couple of fields from the upstream Source/Transformation component as the Input Parameters for our Stored Procedure. For this, you can use the Premium SQL Server Destination component and specify the Stored Procedure as a custom command option.

SQL Server Destination.png

The grid on the left side can be used to select, drag, and drop the required input columns to the command window. Once done, navigate to the Output page, and here, you can add the column name followed by the respective Output parameter name that needs to be assigned to that column. The green "+" sign can be used to add more fields.

SQL Server Destination - Output parameters.png

When the data flow is executed, you will see that the Stored Procedure is executed successfully, and the Output Parameters are assigned and returned as columns in the default output of the SQL Server Destination component.

SQL Server Destination Flow.png

The columns can now be used in your data flow design as required.

Conclusion

As demonstrated above, using our Premium SQL Server components, you can easily execute and handle the Output Parameters from Stored Procedures. This gives you the flexibility to perform complex logical designs with ease in either the Control Flow or the Data Flow, by simply using our components' intuitive UI.

We hope this has helped!

Archive

April 2025 3 March 2025 1 February 2025 1 January 2025 2 December 2024 1 November 2024 3 October 2024 1 September 2024 1 August 2024 2 July 2024 1 June 2024 1 May 2024 1 April 2024 2 March 2024 2 February 2024 2 January 2024 2 December 2023 1 November 2023 1 October 2023 2 August 2023 1 July 2023 2 June 2023 1 May 2023 2 April 2023 1 March 2023 1 February 2023 1 January 2023 2 December 2022 1 November 2022 2 October 2022 2 September 2022 2 August 2022 2 July 2022 3 June 2022 2 May 2022 2 April 2022 3 March 2022 2 February 2022 1 January 2022 2 December 2021 1 October 2021 1 September 2021 2 August 2021 2 July 2021 2 June 2021 1 May 2021 1 April 2021 2 March 2021 2 February 2021 2 January 2021 2 December 2020 2 November 2020 4 October 2020 1 September 2020 3 August 2020 2 July 2020 1 June 2020 2 May 2020 1 April 2020 1 March 2020 1 February 2020 1 January 2020 1 December 2019 1 November 2019 1 October 2019 1 May 2019 1 February 2019 1 December 2018 2 November 2018 1 October 2018 4 September 2018 1 August 2018 1 July 2018 1 June 2018 3 April 2018 3 March 2018 3 February 2018 3 January 2018 2 December 2017 1 April 2017 1 March 2017 7 December 2016 1 November 2016 2 October 2016 1 September 2016 4 August 2016 1 June 2016 1 May 2016 3 April 2016 1 August 2015 1 April 2015 10 August 2014 1 July 2014 1 June 2014 2 May 2014 2 February 2014 1 January 2014 2 October 2013 1 September 2013 2 August 2013 2 June 2013 5 May 2013 2 March 2013 1 February 2013 1 January 2013 1 December 2012 2 November 2012 2 September 2012 2 July 2012 1 May 2012 3 April 2012 2 March 2012 2 January 2012 1

Tags