HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

SSIS: Passing variable from child package to parent package

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
packagepassingssisparentchildfromvariable

Problem

I have an SSIS project consisting of many packages, including a Main_Flow package which executes the other packages in the desired order.

The first package to be called from Main_Flow is Extract_Archive with a ForEach container that looks for zipped files. If one or more zip file exists, it extracts them in a location and marks a variable ArchiveFileFound to TRUE.

Now back in the Main-Flow package, I would like the next step to be executed ONLY if the ArchiveFileFound from the Extract_Archive is set to TRUE. However that variable only exists in Extract_Archive. I've been looking for information on how to pass variables from one SSIS package to another but I cannot find a good practical and recommended example. Any thoughts?

Solution

This can be done using a Script Task in the child package to update a variable from the parent package based off the value of a variable in the child package, assuming that none of the variables that are accessed have the same name in both the parent and child packages. While the variables from the parent package won't be displayed in the ReadWriteVariables field on the Script Task, if you enter them here then they can be accessed. Updating the variables from the parent package would follow the same syntax as doing so for variables in the same package, and the C# example details this.

Dts.Variables["User::ParentVariable"].Value = Dts.Variables["User::ChildVariable"].Value;

Code Snippets

Dts.Variables["User::ParentVariable"].Value = Dts.Variables["User::ChildVariable"].Value;

Context

StackExchange Database Administrators Q#220986, answer score: 4

Revisions (0)

No revisions yet.