Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following sql statement that works when I execute it in the query window on the access interface, however when I run this from code, it returns nothing.

Select [IngredientID],[Ingredient] from [Ingredients] where [Ingredient] Like '*a*'

I can't see anything wrong with it. Any help will be appreciated.

What I have tried:

I tried using double quotes, and that didn't work. Also tired the fields with or without brackets, and that didn't work either.
Posted
Updated 18-Jan-20 2:33am
Comments
MadMyche 18-Jan-20 8:22am    
Posting the actual C# code would be helpful
[no name] 18-Jan-20 8:24am    
Do you get any data if you do not restrict, I mean if you do Select [IngredientID],[Ingredient] from [Ingredients] ?

1 solution

SQL LIKE wildcards don't use "*" - they use "%" instead.
Try this:
SQL
SELECT [IngredientID],[Ingredient] FROM [Ingredients] WHERE [Ingredient] LIKE '%a%'
 
Share this answer
 
Comments
[no name] 18-Jan-20 8:43am    
But according to the MS Access docs it is '*'
OriginalGriff 18-Jan-20 8:48am    
Yes, but - you have to wonder if his actual code is, or if it's using SQL Server to handle the Access file, maybe via an ATTACH connection? Given it "returns nothing", it doesn't seem to be throwing an error, just not finding any matches.
MadMyche 18-Jan-20 12:10pm    
Depends on the Docs you are reading; as Access can support both it's "enhanced" SQL as well as ANSI SQL.
https://docs.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/comparison-of-microsoft-access-sql-and-ansi-sql
[no name] 19-Jan-20 8:20am    
I see, thank you for this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900