Solved

Problem with   LIKE operator

Posted on 1998-03-09
9
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 20 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

630 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