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

  • Thread starter גנן גידל דגן
  • 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.
 
D

Douglas J. Steele

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*"
 
J

Jeff Boyce

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top