using a declared variable in an ssis expression
Is it possible to use a variable inside an expression such as
"declare @name varchar(50)
set @name = (select name from people where acctid='abc')
select * from b where" + @[User::var]+"="+@name"
December 27th, 2010 4:03pm
of course you can.
where you want to use it?
in an execute sql statement or oledb source?
or as another variable expression?http://www.rad.pasfu.com
Free Windows Admin Tool Kit Click here and download it now
December 27th, 2010 4:09pm
Using it in a Execute Sql task
Actually I am using it in an update statement
"update @[User::strTableName]+"
set uid = p.uid
from pb_stage p with (nolock)
where p.account="+ @[User::strTableName]+".["+@acctname+"]"
but I get an expression cannot be parsed error
December 27th, 2010 4:42pm
"update " +
@[User::strTableName]+"
set uid = p.uid
from pb_stage p with (nolock)
where p.account="+ @[User::strTableName]+".["+@acctname+"]"
From the snippet you posted, you need to put a quote and plus sign on the table name on the first line.Please mark answered posts. Thanks for your time.
Free Windows Admin Tool Kit Click here and download it now
December 27th, 2010 4:47pm
in addition to what Eric suggested, you can use new variable of string type, and put everything Eric suggested into this new variable expression property, and set EvaluateAsExpression to true, then in execute sql task just use the new variable as sourcehttp://www.rad.pasfu.com
December 27th, 2010 4:50pm
I changed the update statement and now I get the variable acctname was not found in the variables collection. However I do declare it
at the top of the sql statement
"declare @acctname varchar(50)
set @acctname = (select columnname from sc_col_map where colid='Account')
update....
Free Windows Admin Tool Kit Click here and download it now
December 27th, 2010 5:08pm
tell us what is your sql statement EXACTLY and Totally? ( each of your posts have a portion of sql statement )http://www.rad.pasfu.com
December 27th, 2010 5:16pm
sorry about that
"declare @acctname varchar(50)
set @acctname = (select columnname from sc_col_map where colid='Account')
update "+ @[User::strTableName]+"
set uid = p.uid
from pb_stage p with (nolock)
where p.account= "+ @[User::strTableName]+".["+@acctname+"]
and p.company in ('" + @[User::company]+" ')"
I am trying to update a dynamically named table with a uid from table pb_stage. Column names are dynamic.
The literal string would be
update MyTable
set uid=p.uid
from pb_stage with (nolock)
where p.account=MyTable.MyAcct
and p.company in ('MyCompany')
Free Windows Admin Tool Kit Click here and download it now
December 27th, 2010 5:29pm
create new variable in package scope of string data type, name it for example MySQLStatement,
then right click on this variable, select properties, in the properties window, set Expression property with this statement:
"declare @acctname varchar(50)
set @acctname = (select columnname from sc_col_map where colid='Account')
update "+ @[User::strTableName]+"
set uid = p.uid
from pb_stage p with (nolock)
where p.account= "+ @[User::strTableName]+".["+@acctname+"]
and p.company in ('" + @[User::company]+" ')"
then set EvaluateAsExpression property to true,
then in execute sql task, set source From Variable, and set MySQLStatement variable there.
http://www.rad.pasfu.com
December 27th, 2010 5:34pm