• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2664
  • Last Modified:

Passing a variable into a DataReader Source

I have an SSIS build that runs an "Execute SQL Task" in Control Flow,  The Execute SQL Task pulls a date from the database.  In Data Flow I have a DataReader Source object that queries a DB2 database table where the entry date is greater than the variable I get from the "Execute SQL Task".

How do I pass the variable from the "Execute SQL Task" to the SQL statement in the DataReader Source object in "Data Flow"?

My Data Flow source reader SQL statement is
Select * from <tablename> where entrydate > @User::iDateLoadRange

The above SQL statement will not validate.

1 Solution
Create additional package level string variable (let's name it DB2Query, set its value to a valid DB2 SELECT query - it is important that it should be a auery like SELECT * FROM <tablename>, where <tablename> is your table in DB2 database, because then you will be able to set the proper mappings in Data Flow Task). After Execute SQL Task put a Script Task in your package. In Script Task put iDateLoadRange into ReadOnlyVariables property and DB2Query variable into the ReadWriteVariables property.

Then design the script so it should look like:

Public Sub Main()
        Dts.Variables("User::DB2Query").Value = "SELECT * FROM <tablename> WHERE entrydate > " & _
        Dts.TaskResult = Dts.Results.Success
End Sub

If the date in DB2 must be past in some kind of quotes, you need to edit the code above (just remember that & is a concatenation in VB.NET and you should make it).

Then click on the Data Flow Task which contains your DataReader Source and data transfer from DB2 and look for Expressions property in Properties window. Configure it so the [DataReader].[SqlCommand] value is equal @[User::DB2Query].

This should work (honestly I have never tried it like this).
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now