简体   繁体   中英

Using a variable in a lookup in SSIS

I am trying to do a loop through a few data flow tasks. With each loop it increases the date variable by 1 (which is stored in a variable). Inside the data flow tasks I have a lookup task that is supposed to use the variable which is being incremented as part of the sql statement, something like this:

Select
    *
From
    Table
Where
    Date = @[User::Date]

But this doesn't work, I get this error:

Must declare the scalar variable "@".

Any help in trying to get this variable into the sql of the lookup would be greatly appreciated. I've also tried using parameters within the lookup but also get an error saying there isn't enough parameters

Use a derived column before the lookup and the set the value of the new column to the variable. Then in the lookup transform you can just do a straight mapping with the new derived column and the date column in your table and lookup intended columns.

In your case it looks like you would need to use SQL due to the nature of your requirement. Hence after changing your Cache Mode to Partial Cache, go to advanced tab and change your SQL to -

Select * 
From Table 
Where Date <> ?

Click on parameters button and map your derived column to Parameter0. Hence the Lookup Match output would now essentially give you all the dates that does not match your derived column that is set by the variable @[User::Date].

You could use a logical expression in a derived column component to check the dates and assign a bool value to a new column then use a conditional split to parse records and modify the data flow.

Image: Derived column expression example

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM