PARAMETERS
Declares parameters at the start of a statement, so that names in the statement are read as parameters rather than as columns.
Access SQL. ACE accepts this clause as written here.
Syntax
Section titled “Syntax”PARAMETERS parameter_name data_type [ , … ] ;statementArguments
Section titled “Arguments”parameter_name
Section titled “parameter_name”The name of a parameter. It is an identifier (pCountry, [first name]), an @ name (@minPrice), or a
chain that names an Access form control ([Forms]![frmOrders]![txtFrom]).
data_type
Section titled “data_type”The parameter’s type, written as for a column in CREATE TABLE: TEXT(15), LONG,
DATETIME, CURRENCY and so on.
statement
Section titled “statement”The query the clause belongs to: a SELECT, INSERT, UPDATE or DELETE. The ; that ends the clause is
required, and the statement follows it.
Remarks
Section titled “Remarks”Without a PARAMETERS clause, a plain name such as pCountry in a WHERE clause is read as a column, and the
statement fails if there is no such column. With the clause, every reference to a declared name is a parameter,
and its value comes from the command’s parameters by name.
A form control such as [Forms]![frmOrders]![txtFrom] can only be reached as a declared parameter. Its value is
supplied under the name with its brackets removed and its parts joined by !: Forms!frmOrders!txtFrom. As in
ACE, a reference matches the declaration whether its parts are joined by ! or ..
A statement fails with “No value was supplied for parameter” when a declared parameter has no value.
The clause and its statement are one statement, even though a ; separates them. An ADO.NET command that holds
both runs them together.
When LibRed reads back a stored procedure that declares parameters, it reads it as its query with a
PARAMETERS clause in front. To store a parameterised query, use
CREATE PROCEDURE.
Differences from ACE
- ACE makes a form control that a query does not declare an implicit parameter. LibRed does not: declare it.
Examples
Section titled “Examples”These run against the Northwind sample database, as in the playground. Each needs the command to supply a value for its parameters.
Find the customers in a country, with pCountry set to Norway:
PARAMETERS pCountry TEXT(15);SELECT CustomerID, CompanyName FROM Customers WHERE Country = pCountryTwo parameters, with pCountry set to UK and pCity to Cowes:
PARAMETERS pCountry TEXT(15), pCity TEXT(15);SELECT CustomerID FROM Customers WHERE Country = pCountry AND City = pCityA form control, with Forms!frmOrders!txtFrom set to a date:
PARAMETERS [Forms]![frmOrders]![txtFrom] DATETIME;SELECT COUNT(*) FROM Orders WHERE OrderDate >= [Forms]![frmOrders]![txtFrom]