Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

using wildcard character in query

Question posted by: dstyles7 (Newbie) on March 8th, 2007 04:31 PM
i created a list box and text box with a command button below
the txt box is used to find info in the list box . i created a sql stament that does this. however i would like to create a wild card where if someone enters caracters from a-z it will pull up a record. below is my current sql statement


SQL = "SELECT LWFieldKey, LWTableLink, LWTableName, [LWFieldName_4], [Field Description] " & _
"FROM LWTABLES INNER JOIN LWFIELDS ON " & _
"LWTABLES.LWTableKey = LWFIELDS.LWTableLink " & _
"WHERE [LWFieldName_4] = '" & txtlwField & "' OR " & _
"[Field Description] = '" & txtlwDescription & "'"
ronverdonk's Avatar
ronverdonk
Moderator
4,139 Posts
March 8th, 2007
05:40 PM
#2

Re: using wildcard character in query
Quote:
however i would like to create a wild card where if someone enters caracters from a-z it will pull up a record.

I suppose you mean a wildcard character like an asterisk (*).
In a MySQL query you can use the LIKE attribute. E.g.

Expand|Select|Wrap|Line Numbers
  1. # Search for all records with field starting with chars ABC
  2. SELECT * FROM table WHERE field LIKE 'ABC%'
  3. # Search for all records with field containing ABC
  4. SELECT * FROM table WHERE field LIKE '%ABC%'
  5. # Search for all record with field ending with ABC
  6. SELECT * FROM table WHERE field LIKE '%ABC

When you are interested you could also use a regular expresion.

Ronald :cool:

Reply
dlite922's Avatar
dlite922
Site Addict
561 Posts
June 29th, 2008
05:23 AM
#3

Re: using wildcard character in query
Quote:
I suppose you mean a wildcard character like an asterisk (*).
In a MySQL query you can use the LIKE attribute. E.g.

Expand|Select|Wrap|Line Numbers
  1. # Search for all records with field starting with chars ABC
  2. SELECT * FROM table WHERE field LIKE 'ABC%'
  3. # Search for all records with field containing ABC
  4. SELECT * FROM table WHERE field LIKE '%ABC%'
  5. # Search for all record with field ending with ABC
  6. SELECT * FROM table WHERE field LIKE '%ABC

When you are interested you could also use a regular expresion.

Ronald :cool:


I was curious, could you use the wild character with the IN() match.

For example could you do

WHERE name IN ("Tho%","%Mc%")

I tried it and it didn't work, is it LIKE IN ( ) or something?

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,919 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top MySQL Forum Contributors