Question : passing variable with in a variable in sql server 2008

Hi,

how to make the below query to work....

declare @var varchar(10),@search varchar(50)
set @var ='a%'
set @search = 'where name like ' +@var     -- (i know this is wrong)

select * from table @search
(above query should be traslated into " select * from table where name like 'a%' )

Thanks



Answer : passing variable with in a variable in sql server 2008

hmmm
1:
2:
3:
4:
5:
declare @var varchar(10),@search varchar(50)
set @var ='a%'
set @search = 'where name like ''' +@var  + ''' '

exec('select * from table ' + @search)
Random Solutions  
 
programming4us programming4us