Microsoft Jet wildcards: asterisk or percentage sign?

旧城冷巷雨未停 提交于 2019-11-26 02:14:52

问题


What is the proper multi-character wildcard in the LIKE operator in Microsoft Jet and what setting affects it (if any)? I am supporting an old ASP application which runs on Microsoft Jet (on an Access database) and it uses the % symbol in the LIKE operator, but I have a customer who apparently has problems in his environment because the % character is understood as a regular character, and I assume that his multi-character wildcard is *. Also, I\'m almost sure that in the past I have written application with queries using * instead of %. Finally, Microsoft Access (as an application) also works only with * and not % (but I\'m not sure how relevant it is).

I just spent about 20 minutes searching the Internet without any useful results, and so I thought it would be useful ask on stackoverflow. Somebody may already know it, and it\'s better to keep the potential answers on stackoverflow than any other random discussion forum anyway.


回答1:


The straight answer is that the behaviour of the wildcard characters is dependent on the ANSI Query Mode of the interface being used.

ANSI-89 Query Mode ('traditional mode') uses the * character, ANSI-92 Query Mode ('SQL Server compatibility mode') uses the % character. These modes are specific to ACE/Jet and bear only a passing resemblance to the ANSI/ISO SQL-89 and SQL-92 Standards.

The ADO interface (OLE DB) always uses ANSI-92 Query Mode.

The DAO interface always uses ANSI-89 Query Mode.

When using ODBC the query mode can be explicitly specified via the ExtendedAnsiSQL flag.

The MS Access user interface, from the 2003 version onwards, can use either query mode, so don't assume it is one or the other at any given time (e.g. do not use query-mode-specific wildcard characters in Validation Rules).

ACE/Jet SQL syntax has an ALIKE keyword, which allows the ANSI-92 Query Mode characters (% and _) regardless of the query mode of the interface, however has the slight disadvantage of the ALIKE keyword not being SQL-92 compatible (however ALIKE remains highly portable). The main disadvantage, however, is that I understand the ALIKE keyword is not officially supported (though I can't imagine it will disappear or have altered behaviour anytime soon).




回答2:


If you're using DAO, use asterisk (and question mark for single symbol placeholder). If you're using ADO, use percent sign (and underscore).




回答3:


You may find this useful:

http://msdn.microsoft.com/en-us/library/aa140104(office.10).aspx

In the query design grid and with DAO you use *, with ADO and ASP, you use %




回答4:


Accessing Jet via ODBC, it's not clear to me what wildcards should be used. I'd assume the natural Jet SQL ones (*/?), but since I never use Jet data via ODBC I can't say.

Within Access, as the article Remou cites says, in code, it depends on what data access interface you use -- ADO (which nobody should be using from within Access), you use %/_ , while with DAO (Jet's native interface layer), you use Jet's native wildcards (*/?).

There is an exception in later versions of Access executing SQL within Access. I don't know if it was Access 2002 or 2003 that added it, but nowadays, there is an ANSI SQL 92 compatibility mode that you can turn on. If you do that, the wildcards become %/_ instead of */?. But being able to choose the ANSI mode applies only within Access itself -- as onedaywhen has informed us, you have to choose different data interface libraries to use the different SQL modes, with ADO using the 92 and DAO and ODBC 89.



来源:https://stackoverflow.com/questions/719115/microsoft-jet-wildcards-asterisk-or-percentage-sign

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!