Solved

Problem with   LIKE operator

Posted on 1998-03-09
9
214 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 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
 

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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 …

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now