CURS 4&5S - Create Queries
-
Upload
claudia-ioana -
Category
Documents
-
view
218 -
download
0
Transcript of CURS 4&5S - Create Queries
-
7/30/2019 CURS 4&5S - Create Queries
1/22
Access 2007 create queris
Prof. univ. dr. Pavel NASTASE
Bucharest Academy of Economic StudiesFaculty of Accounting and Management Information Systems
-
7/30/2019 CURS 4&5S - Create Queries
2/22
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.
2
-
7/30/2019 CURS 4&5S - Create Queries
3/22
Create queries
Get answers from your data
Your new asset-
tracking database is
coming along.
You have tables,
relationships, and
data, so the next step
is to build somequeries.
Specifically, youll create select queries. Theyre
components that retrieve and process your data and
display the results in a datasheet.
The query in the picture takes asset data from the first
table, the names of technicians from the second table,
and displays the result in a way that you can consume.
3
-
7/30/2019 CURS 4&5S - Create Queries
4/22
Create queries
The basics of creating select queries
Access provides two
primary ways to create
select queries theQuery Wizard and the
Query Designer.
Regardless of the tool
you use, you follow
some common stepsto create the query.
1 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.
2
4
-
7/30/2019 CURS 4&5S - Create Queries
5/22
-
7/30/2019 CURS 4&5S - Create Queries
6/22
Create queries
Ways to use query results
When you run a select
query, Access displays
the results in adatasheet.
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.
6
-
7/30/2019 CURS 4&5S - Create Queries
7/22Create queries
Ways to use query results
You can also use your
recordsets to provide
data for forms, reports,and even other
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.
7
-
7/30/2019 CURS 4&5S - Create Queries
8/22Create queries
Query a single recordsource
The Query Designer
gives you the most
control over a selectquery.
It also makes it easy to create a query that uses a single
table as a recordsource.
8
-
7/30/2019 CURS 4&5S - Create Queries
9/22Create queries
Query a single recordsource
For example, this type
of query makes it easy
to list your assets andtheir purchase dates,
as shown here.
1
2
On the Create tab, in the Othergroup, 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
-
7/30/2019 CURS 4&5S - Create Queries
10/22Create queries
Query a single recordsource
For example, this type
of query makes it easy
to list your assets andtheir purchase dates,
as shown here.
3 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.
4 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
-
7/30/2019 CURS 4&5S - Create Queries
11/22
Create queries
Make a query ask you for input
The type of query that
you created in the
previous section canreturn a lot of data. A
common way to limit
what the query returns
is to use a parameter.
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
-
7/30/2019 CURS 4&5S - Create Queries
12/22
Create queries
Make a query ask you for input
In other words,
parameters are a type
of filter that you buildin to your query.
1
2
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.
12
-
7/30/2019 CURS 4&5S - Create Queries
13/22
Create queries
Use a formula in a query
Another common way
to alter the selection
criteria in a query is toadd a function.
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 willappear in your results.
13
-
7/30/2019 CURS 4&5S - Create Queries
14/22
Create queries
Use a formula in a query
The picture shows the
process.
1
2
3
Open your query in Design view.
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.
14
-
7/30/2019 CURS 4&5S - Create Queries
15/22
Create queries
Use a formula in a query
The picture shows the
process.
When you run your query, the results include your
calculation.
4
15
-
7/30/2019 CURS 4&5S - Create Queries
16/22
Create queries
Query multiple recordsources
Finally, you can use
multiple tables, or
other queries, as therecordsource for a
new query.
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.
16
-
7/30/2019 CURS 4&5S - Create Queries
17/22
Create queries
Query multiple recordsources
The picture shows the
process.
1
2
On the Create tab, in the Othergroup, click Query
Wizard.
Complete the wizard. As part of that process, select the
tables and fields you want to use as your recordsource,
and ...
17
-
7/30/2019 CURS 4&5S - Create Queries
18/22
Create queries
Query multiple recordsources
The picture shows the
process.
3 Give your new query a descriptive name. Remember to
avoid using spaces in the name.
18
-
7/30/2019 CURS 4&5S - Create Queries
19/22
Create queries
Suggestions for practice
1. Create a select query from a single table.
2. Make the query ask you for input (add a parameter to the query).
3.Add a calculated field to the query.
4. Create a query from multiple tables.
19
-
7/30/2019 CURS 4&5S - Create Queries
20/22
Create queries
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.
20
-
7/30/2019 CURS 4&5S - Create Queries
21/22
Create queries
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.
21
-
7/30/2019 CURS 4&5S - Create Queries
22/22
Create queries
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.
22