Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Tutorial Module 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

TUTORIAL MODULE 2 – QUERYING A DATABASE

Open CMF Vets database.

Creating Queries

To Add Records to the Database

1. Open the Owners table in Datasheet view, and then close the Navigation Pane.
2. Click the open cell below O-2 to enter a new owner ID. Enter the data for all owners below. After
completed, close Owner table.

Figure 1

3. Open the Patients table in Datasheet view, and then close the Navigation Pane.
4. Click the open cell below Patient ID to enter an ID for Patient P-1, Pepper. Enter Pepper’s information.

Figure 2
5. Change the Patient ID numbers for the existing patients so that they are consistent in format.
6. Enter the data for the remaining patients as shown in the figure 2. Close the table once completed.
7. Open the Veterinarians table in Datasheet view, and then close the Navigation Pane.

Figure 3

1|Page
ASM510 – OFFICE SOFTWARE APPLICATIONS
TUTORIAL MODULE 2 – QUERYING A DATABASE

8. Click the open cell below Gomez to enter a new veterinarian last name. Enter the data for Calvin Bennett
as shown in Figure 3, and then enter the data for Mia Rahn-Lee. Close the table once completed.

To Create a Query in Design View


1. Click the ‘Shutter Bar Open/Close Button’ to close the Navigation Pane.
2. Click Create on the ribbon to display the Create tab as shown in Figure 4.

Figure 4
3. Click the Query Design button (Create tab | Queries group) to create a new query, as shown in Figure
5.

Figure 5

4. Ensure the Appointments table (Show Table dialog box) is selected. If it is not, click the Appointments
table to select it.
5. Click the Add button to add the selected table to the query.
6. Click Close to remove the dialog box from the screen.
7. Drag the lower edge of the field list down far enough so all fields in the table appear (Figure 6).

2|Page
ASM510 – OFFICE SOFTWARE APPLICATIONS
TUTORIAL MODULE 2 – QUERYING A DATABASE

Figure 6

To Add Fields to the Design Grid


1. Double-click the Veterinarian field in the field list to add the field to the query.
2. Double-click the Appointment Date field in the field list to add the field to the query.
3. Add the Appointment Time, Patient ID, Treatment Number, and Owner fields to the query (Figure 7).

Figure 7

Determining Criteria
When you use queries, usually you are looking for those records that satisfy some criterion. For example,
you might want to see appointment dates, appointment times, patient ID, types of treatments, and owner
information for one of the veterinarians. You enter criteria in the Criteria row in the design grid below the
field name to which the criterion applies.
For example, to find appointments for Dr. Gomez, you first must add the Veterinarian field to the design
grid. For ease of typing, the veterinarians were given ID numbers, for example, Dr. Teresa Gomez’s ID is
G01, and Dr. William Black’s ID is B01. Therefore, when you enter the Veterinarian ID, you will only need
to type G01 or B01 in the Criteria row. For example, you only need to type G01 for Gomez in the Criteria
row below the Veterinarian field.

To Use Text Data in a Criterion


1. Click the Criteria row for the Veterinarian field to produce an insertion point.
2. Type G01 to specify the criterion (Figure 8).

3|Page
ASM510 – OFFICE SOFTWARE APPLICATIONS
TUTORIAL MODULE 2 – QUERYING A DATABASE

Figure 8
3. Click the Run button (Query Tools Design tab | Results group) to run the query (Figure 9) and display
Dr. Gomez’s appointments.

Figure 9
4. Click the Save button on the Quick Access Toolbar to display the Save As dialog box.
5. Type m02q01 as the name of the query (Figure 10).

Figure 10
6. Click OK (Save As dialog box) to save the query, and then click Close for the m02q01 query to close
the query.

4|Page
ASM510 – OFFICE SOFTWARE APPLICATIONS
TUTORIAL MODULE 2 – QUERYING A DATABASE

To Use a Wildcard
1. Open the Owners Query in Design View.
2. Click the Criteria row below the Owner State field to produce an insertion point.
3. If there were any existing data in the Criteria row, you would use the DELETE or BACKSPACE key. But,
since there is no existing criteria, you can simply type the criteria.
4. Type U* as the criterion (Figure 11).

Figure 11
5. Run the query by clicking the Run button (Query Tools Design tab | Results group).
6. Click File on the ribbon to open the Backstage view.
7. Click the Save As tab in the Backstage view to display the Save As gallery.
8. Click ‘Save Object As’ in the File Types area (Figure 12).

Figure 12

5|Page
ASM510 – OFFICE SOFTWARE APPLICATIONS
TUTORIAL MODULE 2 – QUERYING A DATABASE

9. With Save Object As selected in the File Types gallery, click the Save As button to display the Save As
dialog box.
10. Erase the name of the current query and type m02q02 as the name for the saved query (Figure 13).
Click OK.

Figure 13

To Use Criteria for a Field Not Included in the Results


1. Open the Owners Query in Design view.
2. Type 813* as the criterion for the Owner Postal Code field (Figure14).

Figure 14

3. Click the Show check box for the Owner Postal Code field to remove the check mark.

Figure 15
4. Run the query (Figure 16). Save the result as m02q03.

6|Page
ASM510 – OFFICE SOFTWARE APPLICATIONS
TUTORIAL MODULE 2 – QUERYING A DATABASE

Figure 16

To Create and View a Parameter Query


1. Open the Owners Query in Design view.
2. Click in the Criteria cell for Owner State and enter [Enter CO for Colorado or UT for Utah] as the new
criterion.
3. Click the Run button (Query Tools Design tab | Results group) to display the Enter Parameter Value
dialog box (Figure 17).

Figure 17
4. Type CO as the parameter value in the Enter Parameter Value text box, and then click OK (Enter
Parameter Value dialog box) to close the dialog box and view the query (Figure 18).
5. Click File on the ribbon to open the Backstage view.
6. Click the Save As tab in the Backstage view to display the Save As gallery.
7. Click ‘Save Object As’ in the File Types area.
8. With Save Object As selected in the File Types area, click the Save As button to display the Save As
dialog box.
9. Type Owner-State Query as the name for the saved query.
10. Click OK (Save As dialog box) to save the query with the new name and close the Backstage view.
11. Click Close for the Owner-State Query to close the query.

Figure 18

7|Page
ASM510 – OFFICE SOFTWARE APPLICATIONS
TUTORIAL MODULE 2 – QUERYING A DATABASE

To Use a Number in a Criterion


1. Click Create on the ribbon to display the Create tab.
2. Click the Query Design button (Create tab | Queries group) to create a new query.
3. If necessary, click the Treatment Cost table (Show Table dialog box) to select the table.
4. Click the Add button to add the selected table to the query.
5. Click Close to remove the dialog box from the screen.
6. Drag the lower edge of the field list down far enough so all fields in the list are displayed.
7. Include the Treatment Number, Treatment, Animal Type, and Cost fields in the query.
8. Type 25 as the criterion for the Cost field.

Figure 19

9. Run the query (Figure 20).


10. Save the query as m02q04.
11. Close the query.

Figure 20

To Use a Comparison Operator in a Criterion


1. Start a new query using the Appointments table.
2. Include the Appointment Date, Appointment Time, Treatment Number, Veterinarian, and Patient ID
fields.
3. Type >6/30/2021 as the criterion for the Appointment Date field (Figure 21).
4. Run the query.
5. Save the query as m02q05.
6. Close the query.

8|Page
ASM510 – OFFICE SOFTWARE APPLICATIONS
TUTORIAL MODULE 2 – QUERYING A DATABASE

Figure 21

To Use a Compound Criterion Involving AND


1. Start a new query using the Appointments table.
2. Include the Appointment Date, Appointment Time, Treatment Number, Veterinarian, and Owner
fields.
3. Type >06/30/2021 as the criterion for the Appointment Date field.
4. Type B01 as the criterion for the Veterinarian field (Figure 22).

Figure 22

5. Run the query and Notice that Veterinarian B01 does have an appointment after 6/30/2021.
6. Save the query as m02q06.

To Use a Compound Criterion Involving OR


1. Return to Design view.
2. If necessary, click the Criteria entry for the Veterinarian field and delete any existing text.
3. Click the “or” row (the row below the Criteria row) for the Veterinarian field, delete any existing text
if necessary, and then enter B01 as the entry.

9|Page
ASM510 – OFFICE SOFTWARE APPLICATIONS
TUTORIAL MODULE 2 – QUERYING A DATABASE

Figure 23
4. Run the query (Figure 24).
5. Use Save As to save the query as m02q07.

Figure 24
Sorting
To Clear the Design Grid
1. Click the Design View button to display m02q07 in Design view.
2. Click just above the Appointment Date column heading in the grid to select the column (Figure 25).
3. Press delete to clear the design grid.
4. Close the query without saving these changes.

Figure 25

10 | P a g e
ASM510 – OFFICE SOFTWARE APPLICATIONS
TUTORIAL MODULE 2 – QUERYING A DATABASE

To Import a Table
1. CMF Vets requires additional data to be able to run some of its required queries. As you learned
previously, you can import data from external sources.
2. Import the Veterinarian Vendor table from the CMF Vets Extra Tables database (get the file from
UFuture – Data Files – Module 2).

To Sort Data in a Query


1. Create a new query based on the Treatment Cost table.
2. Include the Treatment and Cost fields in the design grid.
3. Click the Sort row in the Cost field column, and then click the Sort arrow to display a menu of possible
sort orders (Figure 26).
4. Click Ascending to select the sort order.

Figure 26
5. Run the query (Figure 27) to display the treatment costs sorted in ascending order (lowest to highest).

Figure 27
6. Save the query as m02q08.

To Omit Duplicates
1. Click the Design View button to return to Design view.
2. In the design grid, click just above the Treatment field to select the field and then click DELETE to
remove the Treatment field from the query.
3. Click the second field (the empty field to the right of Cost) in the design grid to produce an insertion
point.
4. If necessary, click Design on the ribbon to display the Design tab.

11 | P a g e
ASM510 – OFFICE SOFTWARE APPLICATIONS
TUTORIAL MODULE 2 – QUERYING A DATABASE

5. Click the Property Sheet button (Query Tools Design tab | Show/Hide group) to display the property
sheet (Figure 2–35).

Figure 28
6. Click the Unique Values property box, and then click the Unique Values arrow to display a list of
available choices.
7. Click Yes to indicate that the query will return unique values, which means that each value will appear
only once in the query results.
8. Close the Query Properties property sheet by clicking the Property Sheet button (Query Tools Design
tab | Show/Hide group) a second time.
9. Run the query (Figure 29).
10. Save and close the query.

Figure 29

To Sort on Multiple Keys


1. Create a new query based on the Treatment Cost table and add fields in the following order: Treatment
Number, Treatment, Animal Type, and Cost.
2. Select Ascending as the sort order for both the Animal Type field and the Cost field (Figure 30).
3. Run the query to display the treatment costs sorted first by animal type and then by cost.
4. Save the query as m02q09.

Figure 30

12 | P a g e
ASM510 – OFFICE SOFTWARE APPLICATIONS
TUTORIAL MODULE 2 – QUERYING A DATABASE

To Create a Top-Values Query


1. Return to Design view.
2. If necessary, click Design on the ribbon to display the Design tab.
3. Click the Return arrow (Query Tools Design tab | Query Setup group) to display the Return menu
(Figure 31).
4. Click 5 in the Return menu to specify that the query results should contain the first five rows.

Figure 31

5. Run the query (Figure 32) to display only the first five records.

Figure 32
6. Save the query as m02q010.
7. Close the query.

Joining Tables
To Join Tables
1. Click the Query Design button (Create tab | Queries group) to create a new query.
2. If necessary, click the Appointments table (Show Table dialog box) to select the table.
3. Click the Add button (Show Table dialog box) to add a field list for the Appointments Table to the query
(Figure 33).

Figure 33

13 | P a g e
ASM510 – OFFICE SOFTWARE APPLICATIONS
TUTORIAL MODULE 2 – QUERYING A DATABASE

4. Click the Treatment Cost table (Show Table dialog box).


5. Click the Add button (Show Table dialog box) to add a field list for the Treatment Cost table.
6. Close the Show Table dialog box by clicking its Close button.
7. Expand the size of the two field lists so all the fields in the Appointments and Treatment Cost tables
appear (Figure 34).

Figure 34

8. In the design grid, include the Appointment Date field from the Appointments Table as well as the
Treatment, Animal Type, and Cost fields from the Treatment Cost Table.
9. Select Ascending as the sort order for both the Appointment Date field and the Treatment field (Figure
35).

Figure 35
10. Run the query (Figure 36).

Figure 36
11. Click the Save button on the Quick Access Toolbar to display the Save As dialog box.
12. Enter Appointments and Treatments as the query name.
13. Click OK (Save As dialog box) to save the query.

14 | P a g e
ASM510 – OFFICE SOFTWARE APPLICATIONS
TUTORIAL MODULE 2 – QUERYING A DATABASE

To Change Join Properties


1. Return to Design view.
2. Right-click the join line to produce a shortcut menu (Figure 37).

Figure 37

3. Click Join Properties on the shortcut menu to display the Join Properties dialog box (Figure 2–48)

Figure 38

4. Click option button 3 (Join Properties dialog box) to include all records from the Treatment Cost Table
regardless of whether they match any appointments.
5. Click OK (Join Properties dialog box) to modify the join properties and close the Join Properties dialog
box.
6. Run the query (Figure 2–49).
7. Click the Save button on the Quick Access Toolbar to save the changes to the query.
8. Close the Appointments and Treatments Query.

Figure 39

15 | P a g e
ASM510 – OFFICE SOFTWARE APPLICATIONS
TUTORIAL MODULE 2 – QUERYING A DATABASE

To Create a Report from a Query


1. Open the Navigation Pane, and then select the Appointments and Treatments Query in the Navigation
Pane.
2. Click Create on the ribbon to display the Create tab.
3. Click the Report Wizard button (Create tab | Reports group) to display the Report Wizard dialog box
(Figure 41).

Figure 40

4. Click the ‘Add All Fields’ button (Report Wizard dialog box) to add all the fields in the Appointments
and Treatments Query.
5. Click Next to display the next Report Wizard screen.
6. Because you will not specify any grouping, click Next again to display the next Report Wizard screen.
7. Because you already specified the sort order in the query, click Next again to display the next Report
Wizard screen.
8. Make sure that Tabular is selected as the Layout and Portrait is selected as the Orientation.
9. Click Next to display the next Report Wizard screen.
10. If necessary, erase the current title, and then type Appointments and Treatments Report as the new
title.
11. Click the Finish button to produce the report.
12. Close the Appointments and Treatments Report.

To Create a Form for a Query


1. If necessary, select the Appointments and Treatments Query in the Navigation Pane.
2. Click Create on the ribbon to display the Create tab.
3. Click the Form button (Create tab | Forms group) to create a simple form
4. Click the Save button on the Quick Access Toolbar to display the Save As dialog box.
5. Enter Form at the end of the Appointments and Treatments name so that Appointments and
Treatments Form appears as the complete name.
6. Click OK to save the form.
7. Click Close for the form to close the form.

Figure 41

16 | P a g e
ASM510 – OFFICE SOFTWARE APPLICATIONS

You might also like