PDA

View Full Version : Using the LIKE statement to find similar words


admin
05-30-2003, 07:40 AM
searchstring = Request.Form("search_string")

suppose that searchstring = Donald

The following string will match any last names that have any part of Donald in the string. It would match Donald, McDonald, and Donaldson.

SQL = "SELECT * FROM tblCustomers WHERE LastName LIKE '%" &searchstring& "%'"

The following string will match any last names that have Donald at the end of the string. It would find Donald and McDonald.

SQL = "SELECT * FROM tblCustomers WHERE LastName LIKE '%" &searchstring& "'"

The following string will match any last names that have Donald at the beginning of the string. It would find Donald and Donaldson.

SQL = "SELECT * FROM tblCustomers WHERE LastName LIKE '" &searchstring& "%'"

And of course you could hard-code it into the string as well...

SQL = "SELECT * FROM tblCustomers WHERE LastName LIKE '%Donald%'"