Microsoft Jet wildcards: asterisk or percentage sign?

自闭症网瘾萝莉.ら 提交于 2019-11-26 10:46:07

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).

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

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 %

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.

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