Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 Varible to use in where clause

Author  Topic 

cidr
Posting Yak Master

207 Posts

Posted - 2011-08-25 : 10:53:05
Hi,

I have something that is probably quite strait forward. I have an Xtract table object that loads data from SAP to a SQL table. there is a WHERE clause, and in that where clause I want to use a parameter in the clause that is a date.

The date is a specific date from a table; the max date of the table to be specific. I tried using a SQL task source. This is just a select statement that returns the date in question.

I'm not really sure how to use the returned date in the where clause of the Xtract table or any other query in SSIS for that matter.

Does anyone know how this can be done?

Many thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-25 : 12:56:15
yep. first return the maxdate in execute sql task and assign it to variable added (@[User::MaxDate]). Then add another string variable which holds your query and set evaluate as expression as true for it in properties. then in expression give like

"SELECT ..... WHERE datefield =" (this is your current query) + @[User::MaxDate]

then in your data flow task for SAP source use sql command from variable option and map query variable to it and you're done

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

cidr
Posting Yak Master

207 Posts

Posted - 2011-08-25 : 17:04:14
I don't know what I would do without you Visakh; you've been invaluable through out my IT career.

I'll try it tomorrow and let you know how I get on
:)
Go to Top of Page

cidr
Posting Yak Master

207 Posts

Posted - 2011-08-30 : 05:40:56
Hi Visakh,

I managed to assign the varible - using the Result Set tab in Execute SQL task Editor - to the expression in the SQLStatement option in General tab (is that right?)

Then add another string variable which holds your query and set evaluate as expression as true for it in properties

I'm a little unsure about this bit. Do I create another variable in the Result Set tab and add an expression to it?

Sorry, this is still a bit confusing for me.

Hope you can help further.

Go to Top of Page
   

- Advertisement -