Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8769595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:22:49+00:00 2026-06-13T17:22:49+00:00

I have a stored procedure that gets executed through SQL SSIS using a Execute

  • 0

I have a stored procedure that gets executed through SQL SSIS using a Execute SQL Task.

The task has the following:

USE [OPPY_DWUSD]
GO
DECLARE @return_value int
EXEC    @return_value = [dbo].[generate_merge_scdbk]
    @Schema = N'dim',
    @Dimension = N'VARIETY',
    @ETLSchema = N'stg',
    @ETLTable = N'vw_VARIETY',
    @Execute = 1

SELECT  'Return Value' = @return_value
GO

Right now the way I have this setup, I have multiple Execute SQL Tasks with the same code but different values, about 20 Execute SQL Tasks.

Is there a more cleaner way to pull this off?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:22:50+00:00Added an answer on June 13, 2026 at 5:22 pm

    Here is one way of doing this. The example uses SSIS 2008 R2 with SQL Server 2012 backend.

    Create a table to store your parameter values. Let’s say the table name is dbo.SProcValues. Based on your stored procedure definition, the table schema would look like this.

    CREATE TABLE dbo.SProcValues(
        Id int IDENTITY(1,1) NOT NULL,
        SProcName nvarchar(40) NOT NULL,
        SchemaName nvarchar(20) NOT NULL,
        Dimension nvarchar(40) NOT NULL,
        ETLSchema nvarchar(20) NOT NULL,
        ETLTable nvarchar(40) NOT NULL,
        IsExecute bit NOT NULL
    ) 
    GO
    

    Let’s insert some sample data using the following script.

    INSERT INTO dbo.SProcValues 
        (SProcName, SchemaName, Dimension, ETLSchema, ETLTable, IsExecute) VALUES
        ('dbo.sp_generate_merge', 'dim1', 'dimension1', 'stg1', 'table1', 1),
        ('dbo.sp_generate_merge_scdbk', 'dim2', 'dimension2', 'stg2', 'table2', 1),
        ('dbo.sp_generate_merge_scdbk', 'dim3', 'dimension3', 'stg3', 'table3', 0),
        ('dbo.sp_generate_merge', 'dim4', 'dimension4', 'stg4', 'table4', 0);
    GO
    

    On the SSIS package, assuming that you have the data source and connection manager already established. Create the following variables. Variable SProcValues will hold the parameter set that we stored in the above-mentioned table. Variable SQLInnerQuery will hold the query that will be used later in the inner Execute SQL Task. Other variables relate to each column available in the table so we can loop through each row and hold it in a variable.

    Paste the following query in the value of the variable SQLGetParameters

    SELECT SProcName, SchemaName, Dimension, ETLSchema, ETLTable, IsExecute FROM dbo.SProcValues

    Variables

    Select the variable SQLInnerQuery and press F4 to view the properties. Set the property EvaluateAsExpression to True and then click the Ellipsis button against the Expression property.

    SQLInnerQuery

    We need to set an expression that will evaluate to the EXEC stored procedure statement that can be later supplied to the inner Execute SQL Task. Set the following expression.

    "EXEC " + @[User::SProcName] + " @Schema = ?, @Dimension = ?, @ETLSchema = ?, @ETLTable = ?, @IsExecute = ?"

    If you click Evaluate Expression button on the editor, you can see what the expression will evaluate to. You will also notice that there is no stored procedure name in the below screenshot that is because the package variable SProcName currently does not have any value. During runtime, the SProcName will be assigned with the value from the table and this expression will automatically resolve itself.
    Expression

    On the SSIS package, drag and drop an Execute SQL Task. This task will run the following query to fetch the list of parameter values that are stored in the table dbo.SProcValues. Configure the General page on the Execute SQL Task as shown below. The example uses OLEDB connection and the connection manager/data source is named as Practice.

    First Execute SQL Task - General

    Configure the Result Set page of Execute SQL Task to store the result set from the query to an object variable.

    First Execute SQL Task - Result Set

    Now that the first Execute SQL Task is configured to get the list of parameter values that should be passed to the stored procedure, you need to loop through the records.

    Drag and drop a Foreach Loop container. Connect the Execute SQL Task’s precedence container to the Foreach Loop container. Configure the Collection page of the Foreach Loop container as shown below. We are looping through the result set using the ADO enumerator.

    Foreach loop - Collection

    Configure the Variable Mappings page on Foreach Loop container as shown below. As we loop through each row, we are storing the column values in respective variables so we can pass it to the next Execute SQL Task to run the stored procedure.

    Foreach loop - Variable Mappings

    Drag and drop an Execute SQL Task inside the Foreach Loop container so that this task is executed each time we loop through a row in the result set. Configure the Execute SQL Task as shown below.

    NOTE

    You might want to configure the ResultSet property on this second Execute SQL Task according to your requirements. If you choose ResultSet, then you need to configure an appropriate object variable to accept the result set. I left it as None for this example.

    Second Execute SQL Task - General

    Configure the values to be passed as parameters to the stored procedure.

    Second Execute SQL Task -  Parameter Mapping

    Finally, the control flow would look something like this.

    Control Flow

    When the package runs, the loop will execute the stored procedure for as many records are returned by the SELECT query mentioned above, provided that you have all the stored procedures defined in the table rows are available in the database. I had created the stored procedures dbo.sp_generate_merge_scdbk and dbo.sp_generate_merge with the same parameters definition. That’s the reason the package executed successfully.

    Execution

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that has this line: SET @SQL = 'SELECT path,title,tags
I have a stored procedure that has the parameter: @desk VARCHAR(50) I want to
I have this stored procedure that I want to use for my SAP crystal
I have a stored procedure that gets a list of items, sorts and applies
I have a Stored Procedure that gets some inputs and returns output (was converted
I have a crystal report that gets its data from one stored procedure, this
I have a stored procedure in mysql thats to perform a task that needs
I need to write stored procedure that gets string. Each char in string have
I have a stored procedure in SQL server that looks something like this: insert
I have a stored procedure that gets called hundreds of times per minute. Every

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.