MICROSOFT Access SQL) (PROCEDURE 子句
适用于:Access 2013、Office 2013
定义查询的名称和可选参数。
注意
[!注释] PROCEDURE 子句已经被 PROCEDURE 语句所取代。 虽然现在仍然支持 PROCEDURE 子句,但是 PROCEDURE 语句提供了兼容 PROCEDURE 子句的超集,并且它是推荐使用的语法。
语法
PROCEDURE name [param1 datatype[, param2 datatype[, ...]]
PROCEDURE 子句包含以下部分:
Part | 说明 |
---|---|
name | 过程的名称。 它必须遵循标准命名规则。 |
param1、param2 | 一个或多个字段名或者参数。 例如:PROCEDURE Sales_By_Country [Beginning Date] DateTime, [Ending Date] DateTime; 有关参数的详细信息,请参阅 参数。 |
datatype | 主要 Microsoft Access SQL 数据类型或其同义词之一。 |
说明
SQL 过程由 PROCEDURE 子句(指定该过程的名称)、可选的参数定义列表和一个 SQL 语句组成。 例如,过程 Get_Part_Number 将运行一个用来检索指定配件号码的查询。
注意
示例
本示例将查询命名为 CategoryList,并调用 EnumFields 过程,您可以在 SELECT 语句示例中找到该过程。
Sub ProcedureX()
Dim dbs As Database, rst As Recordset
Dim qdf As QueryDef, strSql As String
' Modify this line to include the path to Northwind
' on your computer.
Set dbs = OpenDatabase("Northwind.mdb")
strSql = "PROCEDURE CategoryList; " _
& "SELECT DISTINCTROW CategoryName, " _
& "CategoryID FROM Categories " _
& "ORDER BY CategoryName;"
' Create a named QueryDef based on the SQL
' statement.
Set qdf = dbs.CreateQueryDef("NewQry", strSql)
' Create a temporary snapshot-type Recordset.
Set rst = qdf.OpenRecordset(dbOpenSnapshot)
' Populate the Recordset.
rst.MoveLast
' Call EnumFields to print the contents of the
' Recordset. Pass the Recordset object and desired
' field width.
EnumFields rst, 15
' Delete the QueryDef because this is a
' demonstration.
dbs.QueryDefs.Delete "NewQry"
dbs.Close
End Sub