like operator in a query (1 Viewer)

cpampas

Registered User.
Local time
Yesterday, 19:41
Joined
Jul 23, 2012
Messages
218
Hello, I would appreciate your help with the folowing :
my query returns these records

maqId descMaq
---------------------------------------------
10 Komatsu PC 130-7K
25 Komatsu PC 130 LC-8
40 Komatsu PC 30
55 Komatsu PC 230LC-6
60 Komatsu PC 130-7K
85 Komatsu PC 130 LC-8
90 Komatsu PC 30MR-3
91 Komatsu PC 30-6

the condition that I set in my query was:

Code:
Like '*komatsu*' And Like '*pc*' And Like '*30*'

I want to get only records numbered 40, 90,91 ( those related to the specific machine Komatsu PC 30)
removing the asterix *, before the string 30 , does not return the desired result ( Like '*komatsu*' And Like '*pc*' And Like '30*')
Is there a way to do this ?
Thanks
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:41
Joined
May 7, 2009
Messages
19,230
(' ' & [descMaq] & ' ') Like '* komatsu *' And (' ' & [descMaq] & ' ') Like '* pc *' And (' ' & [descMaq] & ' ') Like '* 30 *'
 

cpampas

Registered User.
Local time
Yesterday, 19:41
Joined
Jul 23, 2012
Messages
218
hummmm
why didnt I think about that? (y)
Thanks Arnelgp
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 22:41
Joined
Feb 19, 2002
Messages
43,257
Don't break the name into parts
Use:

"*Komatsu PC 30*"

But the best solution is to fix the machine name to be just "Komatsu PC 30" so you don't have to use like. Leave the other characters in a separate field. Using Like * will force a full table scan. The database engine will need to read every single row in your table to evaluate this expression. It will not be able to use any indexes to speed up the search. If your table has only a few hundred rows, it won't matter much but once you get to the thousands, the search will be slow.
 

Users who are viewing this thread

Top Bottom