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 2005 Forums
 Transact-SQL (2005)
 help me...urgent

Author  Topic 

janardhana
Starting Member

4 Posts

Posted - 2008-06-20 : 02:39:38
declare @t1 varchar(50)
set @t1='securityMasterTable'
exec('select securityName from '+ @t1 +' where securityId=1')

if execute the above query then i got


SecurityName
--------------------
HP



my requirement is how to get that value

i want like

declare @name varchar(60)
set @name=???

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-20 : 02:48:45
[code]declare @t1 varchar(50)
set @t1='securityMasterTable'
exec('declare @name varchar(50);select @name=securityName from ' + @t1 + ' where securityid=1;select @name')[/code]
Go to Top of Page

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-06-20 : 02:51:18
Read about sp_executesql and using it for ouput parameter.You can fetch name by making it output parameter.
Go to Top of Page

janardhana
Starting Member

4 Posts

Posted - 2008-06-20 : 03:57:03
quote:
Originally posted by visakh16

declare @t1 varchar(50)
set @t1='securityMasterTable'
exec('declare @name varchar(50);select @name=securityName from ' + @t1 + ' where securityid=1;select @name')



ThanQ friend,
one more doubt plz help me

how can use that variable(@name) later purpose
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-20 : 04:37:38
For use that variable later you need to use sp_executesql
Go to Top of Page
   

- Advertisement -