Académique Documents
Professionnel Documents
Culture Documents
Using Functions
Introduction
To enhance the result produced by a query, you can use some of the built-in functions of
Microsoft Access, including those we saw in Lessons 11-14. You can use a function to
control the values that would display in the query or you can include the functions in the
condition set to filter the values.
To control how the values would display in the query, start a query in Design View or open
a query in Design View. In the bottom section of the window, in the box of the field name,
type the expression. For example, if you have a column named Gender and that display
the genders as Male or as Female but you want to display only M or F respectively, you
can use the Left() function in an expression as Left(Gender, 1):
In the same way, you can use any of the functions we have seen so far.
To use a function in a criterion, open the query in Design View and select the column(s)
you want. In the lower section of the window, click the Criteria box that corresponds to
the column that will hold the criterion and type the expression that includes the function.
For example, on a list of students that includes their dates of birth in a column named
DOB, to get the list of students born in 1994, you would set the condition as
Year([DOB])=1994. Here is an example:
mmary Queries
oduction
get the types of statistics you want, in the Design View of the query, add the same column one more time, and click the
that corresponds to the column:
eality, a summary query uses some of the functions that ship with Microsoft Access:
Count: Microsoft Access uses the Count() function to count the number of occurrences of the category in the column an
produces the total
First: Microsoft Access uses the First() function to get the first occurrence of the value in the category
Last: Microsoft Access uses the Last() function to get the last occurrence of the value in the category
Consider the following table that shows the list of employees and the time they worked:
Consider the following query that wants to summarize the time worked:
Sum: The Sum() function is used to sum up the values in the category
1. In the bottom section of the window, change the header of the second column to
Qty: Category
2. Click its Total combo box and select Count
3. Change the header of the third column to Total Spent: Purchase Price
4. Click its Total combo box and select Sum
5. Change the header of the fourth column to Average: Purchase Price
6. Click its Total combo box and select Avg