Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Why can't I use the Like Predicate

Posted on 1998-07-22
8
Medium Priority
?
282 Views
Last Modified: 2010-05-03
I'm using ADO to connect to an Access 95 database through a DSN.  The problem is I have SQL statement similar to the following

SELECT * FROM [Table] WHERE [FieldName] Like('*" & FieldValue & "*') ORDER BY [FieldName2]

Now there is nothing wrong with the SQL string because if I go into Access and put this as a query it returns the correct records.  The problem is when I run the following line:

  rs.Open sSQL, "DSN=Town;uid=;pwd=", adOpenForwardOnly, adLockReadOnly

I get this error:

Expression cannot be used with the Like predicate. in query expression '[Owner]  alike('*Name*')'.
0
Comment
Question by:PCav
[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
  • 4
  • 2
  • 2
8 Comments
 
LVL 1

Expert Comment

by:BeerMan
ID: 1466400
Try this, i think it's gonna work !

dim query as string
query = "Mr. Jones"   ' Exemple !
query = "*" & query & "*"
"SELECT * From [Table] " & "WHERE [Field] LIKE " & "'" & query & "' "

0
 

Author Comment

by:PCav
ID: 1466401
I no longer get an error, but it doesn't return any records even though there are some that me the criteria.
0
 
LVL 1

Expert Comment

by:wizard2072098
ID: 1466402
Use the same answer as BeerMan gave, but include the asterisks inside the quotes. There's no asterisks in there.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:BeerMan
ID: 1466403
"SELECT * From [Table] " & "WHERE [Field] LIKE " & " ' " & query & " '

The quotes have to be Outside.

0
 

Author Comment

by:PCav
ID: 1466404
They are inside the quotes if you look it say 'query' where query = *Mr.Jones*.
0
 

Author Comment

by:PCav
ID: 1466405
This is what my final SQL Statement evalutes to

SELECT [ID],[Location],[Owner],[Map],[Lot],[Unit] FROM [Town] WHERE  [Owner]  Like '*diesso*' ORDER BY [Owner]

the odd thing is if I run this exact same query in Access it returns one record (which is what it is supposed to do), but doing

rs.open ABOVESQLSTATEMENT, cn, adOpenForwardOnly, adLockReadOnly

where rs is an ADODB.Recordset object and cn is a ADODB.Connection object I get rs.eof evaluting to TRUE.  Now I know the connection to the database is valid because I can run a different SQL Query w/out the like predicate and it returns the way it is suppose to.
0
 
LVL 1

Accepted Solution

by:
wizard2072098 earned 150 total points
ID: 1466406
I know that when you run a LIKE predicate in Transact-SQL on SQL Server, you have to use the "%" instead of "*" as a wildcard character. Maybe you should try changing your asterisks to percent signs and see if it returns something.
0
 

Author Comment

by:PCav
ID: 1466407
Thanks that works.

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

610 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