Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't SQL LIKE work in Microsoft Access?

Tags:

ms-access

I want to my make a search-statement and query things like this

select * from table where col like '%vkvk%' 

But with trial and error I've come to the conclusion that access doesn't work with LIKE or wildcard operators. Does anybody have some other solutions because I ain't so in to access actually, so I really don't know.

like image 669
poo Avatar asked Apr 01 '10 07:04

poo


People also ask

How do I enable SQL in Access?

Right-click the table, feature class, or feature dataset; point to Manage and click Enable SQL Access. A view is created in the database. If you enable SQL access on a feature dataset, one view is created for each feature class in the feature dataset.

Do SQL queries work in Access?

You have selected certain fields in the Query Grid; at the same time, MS Access has also created an SQL Query with the results obtained from your Query Grid. To view the SQL, go to the Home tab. Select SQL View from the View menu and you will see the SQL of your query.

Is SQL like Microsoft Access?

The first thing to understand about Microsoft Access and SQL is that SQL is not an application. Instead, it's a programming language. SQL stands for Structured Query Language. SQL is what your computer uses to communicate with a database like Microsoft Access.

How do you use like operator in Access?

In an expression, you can use the Like operator to compare a field value to a string expression. For example, if you enter Like "C*" in an SQL query, the query returns all field values beginning with the letter C. In a parameter query, you can prompt the user for a pattern to search for.


2 Answers

Try:

select * from table where col like '*vkvk*'

Use an asterisk for the wildcard character.

like image 140
Jay Riggs Avatar answered Sep 23 '22 19:09

Jay Riggs


If you want to use some SQL syntax that is like SQL Server, go to your Access OPTIONS and set it for "SQL 92" mode. So far as I know, this does two main things (there may be others):

  1. allows you to use % and _ as wildcards instead of Jet SQL's * and ?.

  2. allows you to use the non-crazy derived table syntax:

    SELECT MyTable.*
    FROM (SELECT * FROM SomeTable) As MyTable
    

...instead of the bollixed-up Jet method:

   SELECT MyTable.*
   FROM [SELECT * FROM SomeTable]. As MyTable

...which has problems with table and field names with spaces in them, since you have to use brackets inside the derived table definition, which breaks the Jet syntax entirely.

As I said, there may be other things it changes, but if you're a SQL Server programmer, you may find it easier to set SQL 92 mode on. On the other hand, most Access help uses Access/Jet/ACE conventions, so you may end up more confused by trying to use it.

EDIT:

Since originally posting this, I've discovered that there are problems with turning on SQL 92 mode in an existing Access application. The two I discovered were:

  1. It changes the list of reserved words, which means that SQL that previously worked with the SQL 89 list of reserved words can break (if it uses a SQL 92 reserved word).

  2. It can break multi-column combo boxes with a hidden first column (which is a very common UI object in Access applications). Specifically, it breaks the Autoexpend/autoselect behavior.

There may be other problems, but I discovered these accidentally when I turned on SQL 92 mode in a client project to test something for SO and forgot to turn it off when I distributed the next update. Fortunately, the problems were quickly detected, and it didn't take me too long to idenfity SQL 92 mode as the cause of the problems.

In short, I don't consider SQL 92 mode in Access to be of use to anybody at all. It's a feature aimed at people who won't be using Access interactively in the first place, seems to me.

like image 37
David-W-Fenton Avatar answered Sep 19 '22 19:09

David-W-Fenton