By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,766 Members | 1,295 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,766 IT Pros & Developers. It's quick & easy.

How to implement LIKE Clause in Query?

P: 40
I want to find a certain string pattern from database and u`v used the following query for that:
SELECT * FROM myTable
WHERE name LIKE 'a%'

But i want to search a pattern which is been given by the user a the same time. Can there be a variable there with LIKE?
Dec 1 '08 #1
Share this Question
Share on Google+
1 Reply


P: 52
Hi,

u can use

select * from myTable where name like '%' + @Var + '%'

OR

Set @Var = '%' + @Var + '%'

And then you can have your select statement be a simple...

select * from myTable where name like @myVar

AniJos
Dec 1 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.