Looking for a way to refer to a package variable within any Transact-SQL code included in Execut
I'm looking for a way to refer to a package variable within any
Transact-SQL code included in either an Execute SQL or Execute T-SQL
task. If this can be done, I need to know the technique to use -
whether it's something similar to a parameter placeholder question
mark or something else.
FYI - I've been able to successfully execute Transact-SQL statements
within the Execute SQL task, so I don't think the Execute T-SQL task
is even necessary for this purpose.
[512 byte] By [
onamika] at [2008-1-2]
Build another variable to hold the SQL. Then using expressions on that variable, you can concatenate your SQL with the other variable.
For instance:
"SELECT count(*) from " + @[User::MyTableName]
You should be able to use ? as the parameter placeholder, and map a variable to it on the Parameter Mapping tab of the Execute SQL Task.
[edit] I think I misread the question. Phil's suggestion is on the money.
Thanks for the response.
This is fine for simple selects but not very good for more complicated queries that include Transact-SQL, Declare statements, etc. I took the approach of splitting the Exec SQL task into 2 separate ones and using precedence constraints to determine which one to execute.