Posts By Category

Posts By Date

Resources:

C# Books
ASP.NET Books DotNet4All








If you like to support this site, feel free to make a donation to support improvements.

Thank you!

Monetize Your Blog

Wild card % does not work in MS Access for LIKE SQL statement

Using LIKE statement in an SQL query requires specifying wild cards in the search pattern. In C# .NET, the wild card is %, however if you are building your SQL query directly from MS Access, I found out you need to use the asterisk (*) instead of (%) wild card to achieve the same result.

For example, the following SQL statement will return every item whose title contains the word "Microsoft":

SELECT * FROM Items WHERE Title LIKE "%Microsoft%"

The above statement when run from a C# application, it will return all items with the word "Microsoft" contained in their title strings.

In my case, I put the however, I needed to run the SQL query directly from my MS Access database. I found out the % wild card does not work.

Instead, I had to modify my SQL statement as follows:

SELECT * FROM Items WHERE Title LIKE "*Microsoft*"

This is something that has to do with DAO & ADO... any SQL gurus out there that can elaborate further on this?

kick it on DotNetKicks.com

Feedback

Posted on 6/24/2010 11:02:17 AM

"how do you write a query which uses LIKE where the user will be the one to input the word you will look for?"

for example: [Code] SELECT x FROM X WHERE x LIKE [Enter your cats name] [/Code] The [] brackets signals that the query should request user input.

Now to my question, a followup one. How do I create a query using the LIKE critera, allowing for use input, AND using the *Wildcard* symbols on each side of the user input? Ive tried all kinds of combinations LIKE '*[user input]*' etc

Posted on 6/24/2010 11:00:48 AM

"how do you write a query which uses LIKE where the user will be the one to input the word you will look for?"

for example: [Code] SELECT x FROM X WHERE x LIKE [Enter your cats name] [/Code]

Now to my question, a followup one. How do I create a query using the LIKE critera, allowing for use input, AND using the *Wildcard* symbols on each side of the user input? Ive tried all kinds of combinations LIKE '*[user input]*' etc

Posted on 12/12/2008 4:16:10 PM

to gurrrlll: create a second, invisible field on the form then set the On Update property of the first to set the invisible field to the first field plus an *. E.g. field1 = field2 + "*".

What this does is allows the user to enter the first several characters of the value he wants to search for.

Secondly, in your query use a syntax like WHERE ([database].[field] Like [Forms]![form].[field2]);

This has the advantage that you don't need to ask the user to know anything about wildcards.

Posted on 8/18/2008 4:36:42 PM

When using the Reports and creating a query, Can you create a between statement for "Like"?

Posted on 3/1/2008 10:22:14 AM

how do you write a query which uses LIKE where the user will be the one to input the word you will look for?

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 


Copyright © 2007 Yousef Mannaa. All material on this site is copyrighted.
Do not publish or reproduce any of this material without written permission from the Author