Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problem with   LIKE operator

Posted on 1998-03-09
9
Medium Priority
?
278 Views
Last Modified: 2006-11-17
HI,

i want to search wild characters along with the combination of other characters. how do i do that using LIKE operator. i am using Access 7.0. Ex : if the value of the field in the table is having values as, Hello and ?Hello. I want to search the string "?Hello" only. I tried thhis LIKE statement.
SELECT *
FROM <Table>
WHERE<Field> = "bc"
AND <Field1>  LIKE (chr(63) &"*Hello*");
 But this retrieves both the records  with "Hello" and "?Hello".
Similarly i want to use other wild characters(overriding their default meaning). Any suggestions.?

Thanks,
ysgr
0
Comment
Question by:ysgr
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 27

Expert Comment

by:aburr
ID: 1970339
Leave the * out of "*hello*"
0
 

Author Comment

by:ysgr
ID: 1970340
Hi aburr,

i tried removing * in the LIKE statement, which retrieves zero records.
Any other solution?

Thanks,
ysgr
0
 
LVL 12

Accepted Solution

by:
Trygve earned 60 total points
ID: 1970341
Try this SQL:  SELECT [Hello Table].SomeID, [Hello Table].Description
FROM [Hello Table]
WHERE ((([Hello Table].SomeID)=Chr(63) & "Hello"));

Hope this helps !
Trygve
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Expert Comment

by:johnsen
ID: 1970342
The special characters left bracket ([), question mark (?), number sign (#), and asterisk (*) can be used to match themselves directly only by enclosing them in brackets.  The right bracket (]) can't be used within a group to match itself, but it can be used outside a group as an individual character.

Try this SQL:

SELECT *
FROM TEST
WHERE (((TEST.Field1) Like '*[?]Hello*'));

I think this helps!
Johnsen
0
 

Expert Comment

by:Skor
ID: 1970343
I tested Like "[?]Hello" as criteria and only got "?Hello", I did not get "*Hello" or "Hello".

--Skor
0
 
LVL 12

Expert Comment

by:Trygve
ID: 1970344
My proposed answer also gives you the correct records, as far as I can see. But of course the "bracket solution" is more visual and perhaps easier to understand.
0
 

Expert Comment

by:johnsen
ID: 1970345
OKIDO... Trygve
0
 

Author Comment

by:ysgr
ID: 1970346
IT works for wild-characters, still i have problems for chracter |(OR operator).

Thanks,
ysgr
0
 
LVL 12

Expert Comment

by:Trygve
ID: 1970347
The vertical bar | can't be tested for using the bracket solution. You will have to do something like this:

SELECT [Special Characters].TestField, [Special Characters].Description
FROM [Special Characters]
WHERE ((([Special Characters].TestField)=Chr(124) & "Hello"));

Hope this helps !
Trygve
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question