Try to use multi "like statements in a quesry"

T

TonyS.

I'm trying to use the following Like satement within a query to look up more
than one entry in more than one field. Like "*" & [xxxxxxxxx to Search for
Name] & "*", then in another field using a similar selection to look up a
different entry. But every time I try and do this, I don't get past the
first question or lookup..
 
K

Ken Snell \(MVP\)

Something like this:

SELECT *
FROM TableName
WHERE Field1 Like "*" & [Search for Name:] & "*"
AND Field2 Like "*" & [Search for OtherThing:] & "*";
 
M

Marshall Barton

TonyS. said:
I'm trying to use the following Like satement within a query to look up more
than one entry in more than one field. Like "*" & [xxxxxxxxx to Search for
Name] & "*", then in another field using a similar selection to look up a
different entry. But every time I try and do this, I don't get past the
first question or lookup..


That should work. When you add a second criteria similar to
that, you have to decide if you want both to match or if
matching either one is sufficient.

If you want both to match, then put both of them on the same
criteria row. In SQL the WHERE clause would be like this

WHERE fld1 Like *"* & [enter name1] & "*"
AND fld2 Like *"* & [enter name2] & "*"

If only one match is required, then you must put them on
different criteria rows. The generated SQL:

WHERE fld1 Like *"* & [enter name1] & "*"
OR fld2 Like *"* & [enter name2] & "*"
 
Top