an SQL query to search partial matches

  • Thread starter Thread starter aa
  • Start date Start date
A

aa

what would be syntax for an SQL query to search partial matches, compatible
with Access?
I tried WHERE (fieldname LIKE "something") - it did not cause an error, but
returns an empty recordset though there are entries in the field containing
"something" as substring
 
Like requires wildcards for partial matches.

Depending on whether you're using DAO or ADO, try WHERE (fieldname LIKE
"*something*") or WHERE (fieldname LIKE "%something%"). That'll find those
records where the word something appears anywhere in the field. If you want
only those records starting with something, you'd use WHERE (fieldname LIKE
"something*") or WHERE (fieldname LIKE "something%"). For only those records
ending with something, you'd use WHERE (fieldname LIKE "*something") or
WHERE (fieldname LIKE "%something").

There's also _ with DAO (? with ADO) which stands for 1 character. In other
words, WHERE "s*n" would find sun, son, soon and san (among others), while
WHERE "s_n" would only find sun, son and san, not soon.

Check Like in the Help file for more possibilities.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top