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.


liv2007Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

brejkCommented:
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.Variables("User::iDateLoadRange").Value.ToString()
        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).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.