Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 570
Caveman42 Avatar asked Oct 25 '25 10:10

Caveman42


1 Answers

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].

like image 184
TMNT2014 Avatar answered Oct 27 '25 01:10

TMNT2014