Expression | Result |
---|---|
SELECT [FirstName], [LastName] FROM [Employees] WHERE [LastName] = "Davolio"; | Displays the values in the FirstName and LastName fields for employees whose last name is Davolio. |
SELECT [ProductID], [ProductName] FROM [Products] WHERE [CategoryID] = Forms![New Products]![CategoryID]; | Displays the values in the ProductID and ProductName fields in the Products table for records in which the CategoryID value matches the CategoryID value specified in an open New Products form. |
SELECT Avg([ExtendedPrice]) AS [Average Extended Price] FROM [Order Details Extended] WHERE [ExtendedPrice] > 1000; | Displays in a field named Average Extended Price the average extended price of orders for which the value in the ExtendedPrice field is more than 1,000. |
SELECT [CategoryID],Count([ProductID]) AS [CountOfProductID] FROM [Products] GROUP BY [CategoryID] HAVING Count([ProductID]) > 10; |
Displays in a field named CountOfProductID the total number of products for categories with more than 10 products |
Calculate a value using a subquery (SQL statement) | ||||||||
You can use these expressions in a calculated field in a query.
|
||||||||
|
Calculate the average of the values in a field | ||||||||||
Use the Avg and DAvg functions to count the number of records in a domain, such as a query. Use the Avg function when writing SQL statements, and the DAvg function when writing Visual Basic for Applications (VBA) code, macros, and expressions. Note that you can't use these functions in a data access page (data access page: A Web page, published from Access, that has a connection to a database. In a data access page, you can view, add to, edit, and manipulate the data stored in the database. A page can also include data from other sources, such as Excel.). Additionally, you can't use the DAvg function in an Access project (.adp).
|
Examples of conditional expressions | ||||||||||||
The following table lists examples of expressions that you can use in calculated controls (calculated control: A control that is used on a form, report, or data access page to display the result of an expression. The result is recalculated each time there is a change in any of the values on which the expression is based.) on forms, reports, and data access pages (data access page: A Web page, published from Access, that has a connection to a database. In a data access page, you can view, add to, edit, and manipulate the data stored in the database. A page can also include data from other sources, such as Excel.).
|
Calculate the sum of the values in a field | ||||||||||||
Use the Sum and DSum functions to calculate the sum the values in a field in a domain, such as a query. Use the Sum function when writing SQL statements, and the DSum function when writing Visual Basic for Applications (VBA) code, macros, and expressions. Note that you can't use these functions in a data access page (data access page: A Web page, published from Access, that has a connection to a database. In a data access page, you can view, add to, edit, and manipulate the data stored in the database. A page can also include data from other sources, such as Excel.). Additionally, you can't use the DSum function in an Access project (.adp).
|
||||||||||||
|
Count the number of records in an underlying query (MDB) | ||||||||||
Use the Count and DCount functions to count the number of records in a domain, such as a query. Use the Count function when writing SQL statements, and the DCount function when writing Visual Basic for Applications (VBA) code, macros, and expressions. Note that you can't use these functions in a data access page (data access page: A Web page, published from Access, that has a connection to a database. In a data access page, you can view, add to, edit, and manipulate the data stored in the database. A page can also include data from other sources, such as Excel.). Additionally, you can't use the DCount function in an Access project (.adp).
|
||||||||||