Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL using LIKE '*' problem

Status
Not open for further replies.

Doug4Now

Programmer
Apr 22, 2002
34
AU
I am trying to open a recordset - ADO - that selects records on the basis of the first letter of a field eg. I want to find all the clients whose surname begins with "B". My SQL string works fine if I have

Code:
 ...LIKE 'Brown'

- I can see a client whose surname is Brown. However, if I write

Code:
 ...LIKE 'B*'
or
Code:
 ...LIKE '*'

the recordset is empty. It seems as though the "LIKE" operator is working as an "=" operator.

Any ideas about why this is happening and how it can be fixed.

Thanks, Doug.
 
We use LIKE with SQL server and we use % instead of *

There is stuff relating to that in the online books of SQL Server - this may be of use to you:

Using Wildcard Characters as Literals
You can use the wildcard pattern matching characters as literal characters. To use a wildcard character as a literal character, enclose the wildcard character in brackets. The table shows several examples of using the LIKE keyword and the [ ] wildcard characters.

Symbol Meaning
LIKE ‘'5[%]’ 5%
LIKE ‘[_]n’ _n
LIKE ‘[a-cdf]’ a, b, c, d, or f
LIKE ‘[-acdf]’ -, a, c, d, or f
LIKE ‘[ [ ]’ [
LIKE ‘]’ ]
LIKE ‘abc[_]d%’ abc_d and abc_de
LIKE ‘abc[def]’ abcd, abce, and abcf
 
Hi Tom,

It worked - brilliant - thanks for sharing that.

I'm using VB6 with an Access 2000 backend - all the documentation/help files said that * is the wildcard, would never have thought to try % instead - not in a million years!

Thanks again, Doug.
 
I've noticed this too.

I have one application using a MS Access v3 database (created with DAO 3.51) that uses "*" for a wild card, but another I recently created (using ADO 2.7) uses "%". A previous SQL Server application I wrote used "%". I think "%" is the "standard" wild card, as "*" can be used to mean "all fields".

Anyway that's my ha'penny's worth...


Regards,

Andy Watt

"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
 

JET recognizes the * only.

ADO recognizes the % only, but JET interpets it as *

Sql statements can be sent directly to JET over ADO and then the * will be Interpeted correctly.

The ADO Filter method, which is client based and provider independent, can use either, I think.

I think in MS ACCESS, in the Query designer, an * is used, unless using a pass through query.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top