Friday, August 24, 2012

How to pass variable from child package to parent package using SSIS or vice versa

Pass variable from child package to parent package
Please download parent and child package review in detail

  1. Define package Parentpkg  and variable VariableDefinedInParentpkg  with any value
  1. Define package Childpkg and variable VariableDefinedInParentpkg with value 100

  1. Add script task to set VariableDefinedInParentpkg as VariableDefinedInChildPkg
  2. Add script task to set VariableDefinedInParentpkg as VariableDefinedInChildPkg
The key is that you need to manually add User::VariableDefinedInParentpkg  as it can be selected in child package

  1. Pass child variable to parent variable  in script
       public void Main()
       {
           // TODO: Add your code here
Dts.Variables["VariableDefinedInParentpkg"].Value =                                                                            Dts.Variables["VariableDefinedInChildPkg"].Value;
                  Dts.TaskResult = (int)ScriptResults.Success;
       }

  1. Run child package in parent package

MessageBox.Show("User::VariableDefinedInParentpkg:" + Dts.Variables["User::VariableDefinedInParentpkg"].Value.ToString());

  1. Run parent package and get msgbox below




Pass variable from parent package to child package

Please download parent and child package review in detail

  1. Define package Parentpkg  and variable VariableDefinedInParentpkg  with any value

  1. Define package Childpkg and variable VariableDefinedInParentpkg with value 100

  1. Use package configuration to pass value to child


  1. When running package, get value from parent

No comments:

Post a Comment