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
 General SQL Server Forums
 New to SQL Server Programming
 how to use variable in like clause ?

Author  Topic 

java148
Yak Posting Veteran

63 Posts

Posted - 2011-11-28 : 09:43:04
how to use variable in like clause ?
for example :


declare @name varchar(100);
set @name = 'myname';

-- doesn't work
select * from mytable where name like '%@name%'


Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-28 : 10:23:06
it should be

select * from mytable where name like '%' + @name + '%'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

java148
Yak Posting Veteran

63 Posts

Posted - 2011-11-28 : 12:35:16
thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-28 : 12:39:39
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -