IN 子句 (Microsoft Access SQL)IN clause (Microsoft Access SQL)

适用于: Access 2013 | Access 2016Applies to: Access 2013 | Access 2016

标识 Microsoft Access 数据库引擎可连接到的任何外部数据库中的表, 如 dBASE 或 Paradox 数据库或外部 Microsoft Access 数据库引擎数据库。Identifies tables in any external database to which the Microsoft Access database engine can connect, such as a dBASE or Paradox database or an external Microsoft Access database engine database.

语法Syntax

标识目标表To identify a destination table

[选择 |在 { path | 中的_目标位置_插入 "[" path " "类型"] |["" [ type;DATABASE = path ]]]}[SELECT | INSERT] INTO destination IN { path | [" path " " type "] | ["" [ type; DATABASE = path ]]}

标识源表To identify a source table

从 { path | 中的_tableexpression_[" path " "类型"] |["" [ type;DATABASE = path ]]]}FROM tableexpression IN { path | [" path " " type "] | ["" [ type; DATABASE = path ]]}

包含 IN 子句的 SELECT 语句具有以下部分:A SELECT statement containing an IN clause has these parts:

PartPart 说明Description
目标destination 在其中插入数据的外部表的名称。The name of the external table into which data is inserted.
tableexpressiontableexpression 从中检索数据的表的名称。The name of the table or tables from which data is retrieved. 该参数可以是单个表名、存储查询或者从 INNER JOINLEFT JOINRIGHT JOIN 产生的组合结果。This argument can be a single table name, a saved query, or a compound resulting from an INNER JOIN, LEFT JOIN, or RIGHT JOIN.
pathpath 包含表的目录或文件的完整路径 The full path for the directory or file containing table.
typetype 当数据库不是 Microsoft Access 数据库引擎数据库时, 用于创建_表_的数据库类型的名称 (例如, dbase III、dbase IV、Paradox 3. x 或 paradox 4. x)。The name of the database type used to create table if a database is not a Microsoft Access database engine database (for example, dBASE III, dBASE IV, Paradox 3.x, or Paradox 4.x).

备注Remarks

使用 IN 子句一次只能连接一个外部数据库。You can use IN to connect to only one external database at a time.

在某些情况下, _path_参数引用包含数据库文件的目录。In some cases, the path argument refers to the directory containing the database files. 例如, 在使用 dBASE、Microsoft FoxPro 或 Paradox 数据库表时, _path_参数指定包含 .dbf 或 .db 文件的目录。For example, when working with dBASE, Microsoft FoxPro, or Paradox database tables, the path argument specifies the directory containing .dbf or .db files. 表文件名是从 destinationtableexpression 参数得到的。The table file name is derived from the destination or tableexpression argument.

若要指定非 Microsoft Access 数据库引擎数据库,请在名称的后追加一个分号 (;),并用单引号 (' ') 或双引号 (" ") 引起来。To specify a non-Microsoft Access database engine database, append a semicolon (;) to the name, and enclose it in single (' ') or double (" ") quotation marks. 例如,'dBASE IV;' 或 "dBASE IV;" 都是可接受的。For example, either 'dBASE IV;' or "dBASE IV;" is acceptable.

还可以使用 DATABASE 保留字来指定外部数据库。You can also use the DATABASE reserved word to specify the external database. 以下的各行指定了相同的表:For example, the following lines specify the same table:

…FROM Table IN "" [dBASE IV; DATABASE=C:\DBASE\DATA\SALES;]; 

…FROM Table IN "C:\DBASE\DATA\SALES" "dBASE IV;"

示例Example

下面的示例演示如何使用 IN 子句从外部数据库中检索数据。The following example shows how you can use the IN clause to retrieve data from an external database. 在每个示例中,都假设外部数据库中存储了一个假想的 Customers 表。In each example, assume the hypothetical Customers table is stored in an external database.

Microsoft Access 数据库引擎数据库Microsoft Access database engine database

SELECT CustomerID
FROM Customers
IN OtherDB.mdb
WHERE CustomerID Like "A*";

dBASE III 或 IVdBASE III or IV

若要从 dBASE III 表中检索数据,请用 "dBASE III;" 替代 "dBASE IV;"。To retrieve data from a dBASE III table, substitute "dBASE III;" for "dBASE IV;".

SELECT CustomerID
FROM Customer
IN "C:\DBASE\DATA\SALES" "dBASE IV;"
WHERE CustomerID Like "A*";

使用数据库语法的 dBASE III 或 IVdBASE III or IV using database syntax

SELECT CustomerID
FROM Customer
IN "" [dBASE IV; Database=C:\DBASE\DATA\SALES;] 
WHERE CustomerID Like "A*";

Paradox 3. x 或4。Paradox 3.x or 4.x

若要从 Paradox 版本 3.x 表中检索数据,请用 "Paradox 3.x;" 替代 "Paradox 4.x;"。To retrieve data from a Paradox version 3.x table, substitute "Paradox 3.x;" for "Paradox 4.x;".

SELECT CustomerID
FROM Customer
IN "C:\PARADOX\DATA\SALES" "Paradox 4.x;"
WHERE CustomerID Like "A*";

使用 Database 语法的 Paradox 3.x 或 4.xParadox 3.x or 4.x using Database syntax

SELECT CustomerID
FROM Customer
IN "" [Paradox 4.x;Database=C:\PARADOX\DATA\SALES;] 
WHERE CustomerID Like "A*";

Microsoft Excel 工作表A Microsoft Excel worksheet

SELECT CustomerID, CompanyName
FROM [Customers$] 
IN "c:\documents\xldata.xls" "EXCEL 5.0;"
WHERE CustomerID Like "A*"
ORDER BY CustomerID;

工作表中的命名区域A named range in a worksheet

SELECT CustomerID, CompanyName
FROM CustomersRange
IN "c:\documents\xldata.xls" "EXCEL 5.0;"
WHERE CustomerID Like "A*"
ORDER BY CustomerID;

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.