Home > SSIS Best Practices > SSIS – Read or Write to a Variable in Script Task

SSIS – Read or Write to a Variable in Script Task

There are occasions (Debugging is a good reason) when we need to read or write to a variable in a Script Task.

Here are the simple steps to view the row count from a table on your data source:

1) Create a variable varRowCount

2) Create a Data Flow step and a Scrip Task

3) In the Data Flow, use a Table in the data source; Then create a Row Count step, with VariableName set to User::varRowCount

4) In the Scrip Task, enter varRowCount in the ReadWriteVariable field on the Script tab; Then click Design Script and add:

MsgBox("varRowCount: " & Dts.Variables("varRowCount").Value.ToString())

If you need to write to the variable:

     Dts.Variables("varRowCount").Value = 20

     MsgBox("New varRowCount: " & Dts.Variables("varRowCount").Value.ToString())

Categories: SSIS Best Practices
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: