what is wrong with the following SQL syntax using "CONTAINS"?

  • Thread starter Thread starter גנן גידל דגן
  • Start date Start date
×

גנן גידל דגן

Following examples i found on the web i tried to build my own SQL condition
for a query to search all columns in table "a" for the text containing the
word milk.
Here is what i came up with:

SELECT *
FROM [a]
WHERE CONTAINS(*, milk)

I am getting error message: "Syntax error (missing operator) in Query
Expression 'CONTAINS(*,milk)'

what is the missing operator?

i tried replacing "*" with a specific column name but i am still getting the
same error.
 
There is no CONTAINS operator in SQL.

The correct syntax would be

SELECT *
FROM [a]
WHERE [fieldname] = "milk"

or

SELECT *
FROM [a]
WHERE [fieldname] LIKE "*milk*"
 
SQL comes in "dialects" ... Where are you trying to use this?

If you are working completely within Access (front-end and back-end),
perhaps the phrase you're looking for is IN('a','b', ...) instead of
CONTAINS().

.... and if you have a well-normalized table structure, you probably wouldn't
need to be checking "all columns in a table for" a text string.

Take a look at Access HELP for the proper syntax using wildcard characters
in Access.

Good Luck!

--

Regards

Jeff Boyce
Microsoft Access MVP

Disclaimer: This author may have received products and services mentioned in
this post. Mention and/or description of a product or service herein does
not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
Back
Top