Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using LIKE to search multiple fields

Status
Not open for further replies.

JFRobishow

Technical User
Jun 18, 2003
87
CA
Hi,

I have been trying to get this SQL query to work for a while now and it always return 0 record. I'm trying to search multiple fields for a keyword stored in an array like this:

sql2 = "SELECT * FROM table_name WHERE (type=1 AND desc LIKE '%"+arrKeyWords(0)+"%') OR (type=1 AND mc1 LIKE '%"+arrKeyWords(0)+"%')"

type=1 is a flag that is either 0 or 1 but I want results that are flagged as 1. Now this is working fine if the keyword is found in desc but not mc1.

What is the correct syntax to search in two fields?

The string then go in a "for loop" that add the other keywords to the query using UNION. If I can get the first one to work the rest should be a breeze.


 
Try this:

sql2 = "SELECT * FROM table_name
WHERE (type='1' AND des LIKE '%"&arrKeyWords(0)&"%')
OR (type='1' AND mc1 LIKE '%"&arrKeyWords(0)&"%')"

Dont use 'desc' because it is a key word.

Hope that helps

Thanks

VJ

 
Hi,

Thanks I got it now it seems to be working. Didn't know desc was a keyword, I'll make the change.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top