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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using LIKE in WHERE clause

Status
Not open for further replies.

TomSnider

Programmer
May 2, 2001
27
US
I am using Access 2000 with VB6 and I am trying to use the LIKE operator....and it is not working for me. The sql statement is: "SELECT lastname, firstname from PERSONS WHERE lastname like '*SM*'" I was expecting the results to include any record with 'lastname' having the string "SM" in it. However, each time I use the LIKE operator, I get zero records selected. Is the LIKE operator supposed to work with Access2000/VB6?
 
Try the percent sign instead of the asterik.

"SELECT lastname, firstname from PERSONS WHERE lastname like '%SM%'" ljprodev@yahoo.com
Professional Development
MS Access Applications
 

Although Access uses the "*" for the wildcard when searching with the Like predicate, ADO uses the ANSI compliant "%". You are likely using ADO in VB6 and must use the correct ANSI syntax. Terry

X-) "Life would be easier if I had the source code." -Anonymous
 
I think I am using the correct ANSI syntax. I have tried the '*' as well as the '%' and I get no records selected in either case. I have read through 3 books on JET SQL and have looked for hours on the web....and every thing I see is exactly what I am doing. The sql statement I referenced earlier is exactly what I have be generating and I can't see anything wrong with it. This is so frustrating. I am grateful that there are people around to bounce this against, because I don't know what else to do.....I know that I am doing something wrong, like holding my head to the left instead of to the right.......any clues will be greatly appreciated. I am not proud......show me the errors of my ways.......please.
 
Ok, I totally lied. I checked my code and I was still using the '*' instead of the '%' in my sql string. I feel bad for crying like a baby.....but, like I said, I am not proud....my bad.....onward and upward...until the next hurdle....

Tom Snider
San Antonio, Texas
 
Glad you got it fixed. But mainly, welcome to a fellow San Antonian... Terry M. Hoey
th3856@txmail.sbc.com
While I don't mind e-mail messages, please post all questions in these forums for the benefit of all members.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top