| View previous topic :: View next topic |
| Author |
Message |
Denis Marchand Newbie
Joined: 15 Jul 2005 Posts: 6
|
Posted: Jul 15th, 2005 07:35 AM Post subject: Problem with the LIKE operator |
|
|
Hi,
I'm trying to issue an SQL 'SELECT' statement with the 'LIKE' operator from a VB program against a .mdb database. The code is:
Dim rs As Object, SQL
SQL = "SELECT tbl_Test.Ref, tbl_Test.Name FROM tbl_Test WHERE (((tbl_Test.Name) Like 'Mar*') AND ((tbl_Test.Deleted)=False)) ORDER BY tbl_Test.Ref;"
Set rs = CreateObject("ADODB.Recordset")
rs.Open SQL, AdoContacts.ConnectionString, adOpenKeyset, adLockOptimistic '(where AdoContacts is a ADO control on my form)
This query returns an empty set while the same query issued from Access (in an Access Query) returns the correct result.
Yet, if I replace 'LIKE' with '=', then the result is OK (of course not what I want), which kinda shows that there is nothing wrong with the code and the setup (I hope). All my other SELECT statements work. Why doesn't the 'LIKE' one? Any clues?
I use VB 6.0 SP6
Many thanks in advance
Denis[/code |
|
| Back to top |
|
Denis Marchand Newbie
Joined: 15 Jul 2005 Posts: 6
|
Posted: Jul 20th, 2005 03:56 PM Post subject: |
|
|
Ooops! Found the fix by myself: the SQL 'LIKE' operator requres a '%' (percent) charcter as a wildcard, instead of the '*' (asterisk) character I had been using.
Funny that Access accepts the asterisk as a wildcard...
Denis Marchand |
|
| Back to top |
|
blackhd Newbie
Joined: 23 Jul 2005 Posts: 5
|
Posted: Jul 23rd, 2005 01:08 PM Post subject: |
|
|
| ya just abt to tell you to replace the * with % |
|
| Back to top |
|
Denis Marchand Newbie
Joined: 15 Jul 2005 Posts: 6
|
Posted: Jul 24th, 2005 02:22 AM Post subject: |
|
|
OK, thanks!
Denis |
|
| Back to top |
|
|