trying to use LIKE in sql query

johncassell

Well-known member
Joined
Jun 10, 2007
Messages
120
Location
Redcar, England
Programming Experience
Beginner
Hi There,

I have a table 'customers' and a field 'customername'.

I would like to create a query which returns all the results which CONTAIN any given value.

For example, the textbox on my form currently has 'bob' in it.

By executing my query I would like it to return 'bobs transport', 'silly bob media', 'david bob' etc..

In the filter box on the query builder I usually put a ?, but I don't want it to retrieve the exact value this time.

I have tried entering LIKE and %'s and * but none seem to work.

Can someone help please?

Thanks
 
Your SQL would be something like
SELECT * FROM Customer WHERE CustomerName LIKE @CustomerName

Call this query something like FillByLikeCustomerName

Have a textbox like txtCustomerName

Your Fill command will be something like:
Me.CustomerTableAdapter.FillByLikeCustomerName(me.dsCustomer.Customer, "%" & txtCustomerName.text & "%")


(Yes I know, I used the word like a lot...I like it ;) )
 
Back
Top