467,104 Members | 963 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,104 developers. It's quick & easy.

How to implement LIKE Clause in Query?

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
  • viewed: 1688
Share:
1 Reply
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.

Similar topics

2 posts views Thread by steve | last post: by
2 posts views Thread by aj70000@hotmail.com | last post: by
2 posts views Thread by Mike | last post: by
8 posts views Thread by Jerry | last post: by
2 posts views Thread by Jim.Mueksch@wellsfargo.com | last post: by
6 posts views Thread by jackal_on_work@yahoo.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.