Solved

Problem with   LIKE operator

Posted on 1998-03-09
9
256 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

710 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