Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL LIKE operator with parameters and wildcards

I have a query where I want to return all Clients that have a certain string in the name with wildcards on either side. So the input could be "Smith" and i want to return all things like "The John Smith Company" or "Smith and Bros". I want [Client] to be prompted so I set up the SQL like this:

PARAMETERS Client Text ( 255 );
SELECT *
WHERE (((tbl_IncomingChecks.Client) Like'%' + [Client] + '%') 
ORDER BY tbl_IncomingChecks.Client;

The query is not returning any results. Please help

like image 674
Chris568524 Avatar asked Dec 31 '12 19:12

Chris568524


1 Answers

MS Access uses * as a wildcard not %, so your query will be trying to match literal '%' characters. Use * instead unless you are using ADO.

http://office.microsoft.com/en-us/access-help/like-operator-HP001032253.aspx

like image 81
Lord Peter Avatar answered Oct 20 '22 15:10

Lord Peter