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.
Author |
Topic |
DURGESH
Posting Yak Master
105 Posts |
Posted - 2008-06-25 : 01:54:51
|
hello allgood morningi am executing a select query using dynamic sqlexample @sql='select @var=emp from employee where id='''+@id+''''execute(@sql)now i want to store the value of @var into @var2if i am assigning @var2=@var then it is returning nullcan anybody help me to solve this issuethanks in advance |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-25 : 02:03:19
|
You need to use sp_executesql for this. Make the variable @var as of type OUTPUT and you can get its value outside.http://www.sommarskog.se/dynamic_sql.html |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-06-25 : 10:00:31
|
quote: Originally posted by DURGESH hello allgood morningi am executing a select query using dynamic sqlexample @sql='select @var=emp from employee where id='''+@id+''''execute(@sql)now i want to store the value of @var into @var2if i am assigning @var2=@var then it is returning nullcan anybody help me to solve this issuethanks in advance
When you dont pass object names as parameters, you dont need to use dynamic sql at least in the example you have givenMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|