Table of contents
Collapse the table of content
Expand the table of content

Calculating Fields in SQL Functions

office 365 dev account|Last Updated: 6/12/2017
1 Contributor

Applies to: Access 2013 | Access 2016

You can use the string expression argument in an SQL aggregate function to perform a calculation on values in a field. For example, you could calculate a percentage (such as a surcharge or sales tax) by multiplying a field value by a fraction.

The following table provides examples of calculations on fields from the Orders and Order Details tables in the Northwind.mdb database.

Add a number to a fieldFreight + 5
Subtract a number from a fieldFreight - 5
Multiply a field by a numberUnitPrice * 2
Divide a field by a numberFreight / 2
Add one field to anotherUnitsInStock + UnitsOnOrder
Subtract one field from anotherReorderLevel - UnitsInStock

The following example calculates the average discount amount of all orders in the Northwind.mdb database. It multiplies the values in the UnitPrice and Discount fields to determine the discount amount of each order and then calculates the average. You can use this expression in an SQL statement in Visual Basic code:

SELECT Avg(UnitPrice * Discount) AS [Average Discount] FROM [Order Details];

Access for developers forum on MSDN
Access help on
Access help on
Search for specific Access error codes on Bing
Access forums on UtterAccess
Access wiki on UtterAcess
Access developer and VBA programming help center (FMS)
Access posts on StackOverflow

© 2018 Microsoft