CURS 4&5S - Create Queries
CURS 4&5S - Create Queries
Course goals
Use the Query Designer to create a select query that returns data from a single table. Create a select query that asks you to enter parameters, then returns results that match those parameters. Use a formula in a query to calculate a sum. Use the Query Wizard to create a select query that returns data from two tables. Use a text expression to concatenate fields.
Create queries
Create queries
Start by choosing a recordsource for the query. A recordsource can be one or more tables, one or more queries, or a combination of the two. From the recordsource, select the fields that you want to see in the query.
Create queries
Add any sorting, filtering, or other selection criteria to your queries. For example, if you use the criteria shown in the picture, the query will only return data for assets purchased after May First of 2010. After you finish adding fields and any selection criteria, run your query to see if it gives you the correct results.
5
Create queries
The result is called a recordset, and you can work with it in the same way that you work with a datasheet.
For example, you can add or change data, and Access will write your changes to the tables that serve as the recordsources for your query.
Create queries
For example, if you want a report on the computers that you need to replace, you can create a query that returns that data, and then quickly build your report. The picture shows this. The query returns only those records where an asset has been marked for retirement.
Create queries
It also makes it easy to create a query that uses a single table as a recordsource.
Create queries
On the Create tab, in the Other group, click Query Design. The designer starts and displays the Show Table dialog box. In the dialog box, select your recordsource. You can use a combination of tables and queries, and the ones you select appear in the upper section of the designer.
9
Create queries
In your recordsource, double-click the fields that you want to see in your recordset, or results. Your choices appear in the bottom section of the designer.
When you finish adding fields, go to the Design tab on the Ribbon, and in the Results group, click Run. Your record then appears as a datasheet.
10
Create queries
Put simply, parameters make the query ask for input before it runs.
So if, say, you only want to see records between certain dates, you can add parameters that make the query ask you for starting and ending dates. The query will give you just the records that fall between those dates.
11
Create queries
Open the query in Design view, and in the Criteria row of the field you want to filter, enter your parameter. When you run the query, that criteria asks you for a start date, then an end date, and it returns only the records that fall within the dates you specify.
Create queries
12
For example, if you want to know how much your company spent on office furniture last year, you can add an aggregate function to the query and the sum will appear in your results.
Create queries
13
1 2
On the Design tab, in the Show/Hide group, click Totals. The Total row appears in the designer.
In the field where you want to use the function, click the Total row and select a function from the list.
Create queries
14
When you run your query, the results include your calculation.
Create queries
15
The Query Wizard is the easiest way to do that type of job, especially if youre new to Access.
This type of query is a way to answer questions such as which assets came from which suppliers.
Create queries
16
On the Create tab, in the Other group, click Query Wizard. Complete the wizard. As part of that process, select the tables and fields you want to use as your recordsource, and ...
Create queries
17
Give your new query a descriptive name. Remember to avoid using spaces in the name.
Create queries
18
Create queries
19
Test question 1
When you first create a query, you select which of the following? (Pick one answer.)
1. A recordsource.
2. A system table. 3. A recordset.
Create queries
20
Test question 2
Use criteria in a query when you need to do which of the following? (Pick one answer.)
1. Ensure your data is properly formatted. 2. Add formulas to a table. 3. Sort, filter, or otherwise limit what the query returns.
Create queries
21
Test question 3
Before you can use multiple tables as a recordsource, those tables must be or do which of the following? (Pick one answer.) 1. Be open in Datasheet view. 2. Participate in a relationship. 3. Not serve as the recordsource for another query.
Create queries
22