Tutorial 2: Queries and Reports

Similar documents
Tutorial 1: Introduction to Tables, Forms, and Menus

Database Tables Lookup Wizard Relationships Forms Subforms Queries Reports

SOFTWARE SKILLS BUILDERS

Creating a Crosstab Query in Design View

Access Review. 4. Save the table by clicking the Save icon in the Quick Access Toolbar or by pulling

Microsoft Access 2010

Microsoft Access 2010

Microsoft Access 2013

Microsoft Access 2013

Introduction. Inserting and Modifying Tables. Word 2010 Working with Tables. To Insert a Blank Table: Page 1

Skills Exam Objective Objective Number. Creating crosstab queries Create a crosstab query

Microsoft Excel Chapter 2. Formulas, Functions, and Formatting

POS Designer Utility

Getting started with Ms Access Getting Started. Primary Key Composite Key Foreign Key

Switchboard. Creating and Running a Navigation Form

When you pass Exam : Access 2010, you complete the requirements for the Microsoft Office Specialist (MOS) - Access 2010 certification.

Microsoft Office Access Learn how to use the Query window in Design view. Tutorial 3b Querying a Database

Microsoft Word 2013 Working with tables

Microsoft Access 2003 Quick Tutorial

Open Excel by following the directions listed below: Click on Start, select Programs, and the click on Microsoft Excel.

Microsoft Office Illustrated Introductory, Building and Using Queries

Creating User-Friendly Databases

Objective 1: Familiarize yourself with basic database terms and definitions. Objective 2: Familiarize yourself with the Access environment.

CS1100: Data, Databases, and Queries QUERY CONSTRUCTION. CS1100 Microsoft Access 1

Microsoft Access Illustrated. Unit B: Building and Using Queries

Microsoft Excel 2010 Handout

SECTION 4 USING QUERIES. What will I learn in this section?

MS Access Let s begin by looking at the toolbar and menu of Access.

SEE GRADING CRITERIA AT THE BOTTOM. Database Tables Lookup Wizard Relationships Forms Queries Reports

Introduction to CS Dealing with tables in Word Jacek Wiślicki, Laurent Babout,

M i c r o s o f t E x c e l A d v a n c e d. Microsoft Excel 2010 Advanced

THE EXCEL ENVIRONMENT... 1 EDITING...

Microsoft Access 2013

MIS Cases: Decision Making With Application Software, Second Edition. Database Glossary

Nutzen Sie die Dettmer-Seminarunterlagen für Access bei einmaligem Kauf über Jahre hinaus für Ihre eigenen Schulungen

Contents. Group 2 Excel Handouts 2010

Working with Data and Charts

Excel Tutorial 1

Complete Quick Reference Summary

Access Objects. Tables Queries Forms Reports Relationships

Creating and Running a Report

Week 5 Creating a Calendar. About Tables. Making a Calendar From a Table Template. Week 5 Word 2010

Creating and using reports

Enforce Referential. dialog box, click to mark the. Enforce Referential. Integrity, Cascade Update Related Fields, and. Cascade Delete Related

COMPUTER TECHNOLOGY SPREADSHEETS BASIC TERMINOLOGY. A workbook is the file Excel creates to store your data.

Microsoft Access XP Edition for ECDL Syllabus 4.5 (UK only)

Chapter 4. Microsoft Excel

Microsoft Access 2010

Creating a Spreadsheet by Using Excel

WAAT-PivotTables Accounting Seminar

Links to Activities ACTIVITY 3.1. Links to Activities ACTIVITY 3.

Getting Started with Access

Microsoft Access 2003 Edition for ECDL Syllabus 4.5 (UK only)

Creating Reports in Access 2007 Table of Contents GUIDE TO DESIGNING REPORTS... 3 DECIDE HOW TO LAY OUT YOUR REPORT... 3 MAKE A SKETCH OF YOUR

Microsoft Access 2007 Module 2

Step 1: Create a totals query to show the total cost price and total sale price of the wine for each supplier.

Microsoft Access 2007 Level 3

Microsoft Office. Access Tutorial Part 2

Links to Activities ACTIVITY 4.1. Links to Activities ACTIVITY 4.

Microsoft Excel for Beginners

Simple Invoicing Desktop Database with MS Access 2013/2016. David W. Gerbing School of Business Administration Portland State University

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 2 TEXT FORMATTING

-Using Excel- *The columns are marked by letters, the rows by numbers. For example, A1 designates row A, column 1.

SUM, AVERAGE, MEDIAN, MIN,

ADJUST TABLE CELLS-ADJUST COLUMN AND ROW WIDTHS

Formatting Values. 1. Click the cell(s) with the value(s) to format.

Spreadsheet definition: Starting a New Excel Worksheet: Navigating Through an Excel Worksheet

Links to Activities ACTIVITY 4.1. Links to Activities Links to Activities

Add Bullets and Numbers

Unit 2 Fine-tuning Spreadsheets, Functions (AutoSum)

Unit 11.Introduction to Form and Report

PARTS OF A WORKSHEET. Rows Run horizontally across a worksheet and are labeled with numbers.

INSERT SUBTOTALS Database Exercise Sort the Data Department Department Data Tab Sort and Filter Group

MS Office 2016 Excel Pivot Tables - notes

Problem Solving Using Access 2007

PowerPoint Presentation to Accompany GO! All In One. Chapter 13

Budget Exercise for Intermediate Excel

CMPF124 Microsoft Excel Tutorial

Contents. Project One. Introduction to Microsoft Windows XP and Office Creating and Editing a Word Document. Microsoft Word 2003

Microsoft Excel Chapter 1. Creating a Worksheet and an Embedded Chart

STIDistrict Query (Basic)

Microsoft Excel Chapter 1. Creating a Worksheet and a Chart

SmartView. User Guide - Analysis. Version 2.0

Unit 2 Fine-tuning Spreadsheets, Functions (AutoSum)

Excel Project 5 Creating Sorting, and Querying a Worksheet Database

Introduction to Excel 2007

Microsoft Office 2010: Introductory Q&As Access Chapter 2

Candy is Dandy Project (Project #12)

Microsoft Access XP Queries. Student Manual

Word Tutorial 3. Creating a Multiple- Page Report COMPREHENSIVE

Introductory Exercises in Microsoft Access XP

Quick Reference Summary

Kenora Public Library. Computer Training. Introduction to Excel

HKTA TANG HIN MEMORIAL SECONDARY SCHOOL SECONDARY 3 COMPUTER LITERACY. Name: ( ) Class: Date: Databases and Microsoft Access

DB - Week 3 Lab1-2 Introduction to Databases. Dina A. Said

Access 2003 Introduction to Report Design

EXERCISE 1. OBJECTIVES File management. INSTRUCTIONS. Creating Spreadsheets and Graphs (Excel 2003) New CLAIT

SAMPLE. Access 2010 Intermediate. Access 2010 Intermediate. Access 2010 Intermediate Page 1

Connecting SQL Data Sources to Excel Using Windward Studios Report Designer

GO! with Microsoft Access 2016 Comprehensive

Transcription:

Tutorial 2: Queries and Reports This tutorial covers construction of queries using Microsoft Access query by example (QBE) tool and report writer. In this tutorial, you will extend the Infinity Computers order entry system by adding queries and reports. Getting Started Building Queries A query is a request for information based on the contents of the database. Each time the query executes, Microsoft Access produces a recordset that is similar to a table, except a recordset does not use space on disk to store the results. As with other database management systems (DBMS), Microsoft Access provides several ways to create queries. This tutorial focuses on using the QBE grid to create queries. Open OrdEnt2.mdb. To access the QBE grid, go to the Queries tab, click New, select Design View, and click OK. Microsoft Access displays a QBE grid similar to Figure 1. Use this QBE grid to construct or modify queries. Figure 1: Query by Example Tool Query View Button Properties Button Run Button Show Table Button Tables in Query Fields in Query The first step when creating a query is to identify the data sources for the query. Both tables and queries can provide data for new queries; for the sake of brevity from this point on, we use the word table rather than tables and queries. Use the Show Table dialog to select the tables to provide data (Figure 2). When adding tables to a new query, select the minimum number of tables needed to produce the desired information. 1

Figure 2: Adding Tables to a Query Generally, a data model depicts the tables in a database; Figure 3 shows the structure of the database you will use. Use the data model to identify the tables required. Figure 3: Table Structure Double click the Products table. This adds the table to the table section of the QBE grid. Click Close. Double click the ProductID field to add this field to the QBE grid. Add the Description and Price fields 2

to the QBE grid. Click the Run button to execute the query. Your results should look similar to Figure 4. Figure 4: Sample Query 1 Click the small down arrow on the Query Views button and switch back to the QBE grid by selecting Design in the Query Views list (Figure 5). Figure 5: Query Views Save the query by clicking the Save button and then assigning a query name; name the query Sample Query. 3

Click the Show Table button. Double click OrderItems and then click Close. Notice how Microsoft Access automatically shows the relationship between Products and OrderItems (Figure 6). If you have defined a relationship between two tables, Microsoft Access automatically relates the tables whenever you use them together. Double click Quantity and OrderID in the OrderItems table to add these two fields to the QBE grid. Display the results of this new query. The two new fields should appear in the query. Return to the Design View. Save the new query by clicking File and then Save As. Name the updated query Sample Query 2. Figure 6: Related Tables Position the mouse pointer above the OrderID column so that it looks similar to the thick arrow in Figure 7. Click the mouse once to select the column. Hover over the selected column and hold the left mouse button down. Figure 7: Column Selection Drag the mouse left until the location bar (shown as a bold line between the Price and Quantity columns in Figure 8) is left of the ProductID column. Release the mouse button. This repositions the OrderID column to the left-most position in the query. Run the query and verify that the query displays properly. Return to the Design View. 4

Figure 8: Moving Selected Column Click on the Field cell of the first empty column in the QBE grid. Enter the formula shown in Figure 9 to compute the extended price for an order item (Ext Price:Price*Quantity). Microsoft Access uses this formula to compute the extended price for each order item when running the query; as a result, the Ext Price field is like a field in the query s recordset. Figure 9: Derived Field Run the query and check the computation for the first couple of rows in the record set (Figure 10). Figure 10: Computed Extended Price You can set field properties, including the field format and caption. Exercise caution when setting properties in queries since some settings may cause undesired side effects. To set field properties return to Design View and click on the column for the field you want to modify (Ext Price). Next, right click the mouse. Microsoft Access displays a Field Properties dialog (Figure 11). Change the caption for the Ext Price field to ExtPrice (without a space). Run the query and verify that the column heading for the Ext Price field is now ExtPrice. Note that this DOES NOT change the name of the field, just the heading of the column. 5

Figure 11: Field Properties Return to Design View. Add the Orders table to the query. Add the OrderDate field to the QBE grid and move the field to the immediate right of the OrderID field. Use the Between operator to select orders placed between November 1 and November 15, 2002. Type between #11/1/2002# and #11/15/2002# in the Criteria cell for the OrderDate column (Figure 12). Figure 12: Criteria Operator Run the query to display the desired orders (Figure 13). Figure 13: Orders Selected Using a Date Range Save the updated query. 6

You can make a copy of a query before modifying it. This is a good idea if you plan to make extensive changes and want to have a backup of the query prior to the changes. In the Database window, right click the query you want to copy and select Copy in the popup menu (Figure 14). Figure 14: Copy a Query Next click Edit and then Paste. Enter a name for the copy and click OK (Figure 15). This makes an exact copy of the query. This same technique works with forms and reports, as well as other database objects. Figure 15: Paste a Copy 7

Practice Queries Using OrdEnt2.mdb, create the following queries. Where used, format dollar amounts as currency, and commission and discount rates as percents. Once you have each query working, save the query so that you can use it later. Give each query a unique name (e.g., Q01, Q02, ). 1. Display all products in the Products table. Include all fields. 2. Copy the previous query and modify it as follows: move the Description field to the left-most column and sort the results based on the description. 3. Create a query that shows the customer ID, customer name, and discount rate. Format the discount rate as a percent. 4. Copy the previous query and modify it as follows: show only customers with a discount rate equal to 10%. 5. Show the order ID, order date, customer ID (displays as the customer name), and sales rep ID (displays as the sales rep name) for all orders placed on 10/14/2002. 6. Copy the previous query and modify it as follows: show all orders placed during November 2002. 7. Create a query that uses the customers and orders tables. Display the actual customer ID, customer name, order ID, and order date. 8. Copy the previous query and modify it as follows: add the order items table and the product ID (displays as the description of the product). 9. Copy the previous query and modify it as follows: add the products table and the price of the product. 10. Copy the previous query and modify it as follows: add the quantity purchased and compute the extended price for each order item. 11. Copy the previous query and modify it as follows: remove the price and quantity from the QBE grid. 12. Copy the previous query and modify it as follows: sort the orders in ascending order by order ID and compute the total for each order. (Hint: Compute the order total using the aggregate functions feature by clicking the Totals button.) 13. Copy the previous query and modify it as follows: add the sales reps table, sales rep ID, sales rep name, and commission rate between the customer name and extended price fields. 14. Copy the previous query and modify it as follows: compute the commission for the sales person for each order. 15. Create a new query that uses the sales reps table and the previous query. Compute the total commission owed to each sales person. (See the hint for query 12.) 8

16. Copy the previous query and modify it as follows: show all sales reps even if the sales rep does not have any sales. To do this, double click the line connecting the SalesReps table and the query. Select the join property that includes all sales reps and only the records from the query where the joined fields are equal. (FYI: You create a join whenever you build a query consisting of multiple related tables, queries, or combinations of tables and queries.) 9

Getting Started with Reports Queries combine data from multiple tables to produce information. The output of a query is a recordset that looks similar to a table. To present information in a more usable format, Microsoft Access provides a report-generating feature. Continue using OrdEnt2.mdb. To access the reporting tool, go to the Reports tab, click New, select Report Wizard, select a table (Customers), and click OK (Figure 16). Figure 16: Microsoft Access Report Wizard Microsoft Access displays the report wizard dialog similar to Figure 17. Copy the CustID, CustName, and DiscountRate fields to the report by clicking each field and then clicking the single arrow pointing to the right (>). Figure 17: Tables and Fields Add the Orders table to the query using the Tables/Queries drop down list as shown in Figure 18. Add the OrderID and OrderDate fields to the report. Click the Next button. 10

Figure 18: Additional Table Providing Data for a Query Organize the overall grouping of records on the report by customer (Figure 19) and click Next. This example organizes orders by customer. Figure 19: Record Organization Depending on the number of tables in the report and the relationships among the tables, you can partition records by defining grouping levels (Figure 20). Accept the default grouping where customer information is the highest group and order information is the next group. Each grouping level provides a new, more specific detail section on the report. Click Next. 11

Figure 20: Record Grouping If you want to sort records within the lowest grouping level (detailed records), specify the field or fields to use for sorting. Select the OrderID field and click Next (Figure 21). Figure 21: Sort Order The report wizard provides a variety of record layouts (Figure 22). Depending on the number of grouping levels and the number of fields common between levels, different layouts may be appropriate. For this example select Block, even though the block layout is not necessarily a good choice here. Select Landscape for page orientation. Click Next. 12

Figure 22: Layout of the Report Specify the fonts and colors used on the report (Figure 23). I suggest you look at the various styles provided by the report wizard. For this example, select Formal. Click Next. Figure 23: Specify the Report Style Specify the title for the report (Figure 24). The report wizard also uses the title as the name of the report when it saves the report. When you click Finish, the report wizard generates the report. 13

Figure 24: Report Title Once the report is ready, the report wizard displays a preview of the report (Figure 25). Figure 25: Report Preview Microsoft Access provides a Report Design View that enables you to modify the format of the report (Figure 26). 14

Figure 26: Report Design View Figure 27 shows a report modified using the Report Design View. Figure 27: Updated Report Reports Using OrdEnt2.mdb, create the following reports. 1. Create a report called Customer List that includes the CustID, CustName, CustState, and DiscountRate fields. Do not group records. Sort by the customer ID. 15

2. Create a report called Customers with a 10% Discount that uses query 4 as the data source and displays the CustID, CustName, and DiscountRate fields. Do not group records. Sort by the customer ID. 3. Create a report called Customer Orders Totals that uses query 12 as the data source and displays the OrderId, OrderDate, CustName, and Ext Price fields. Do not group records. Sort by the order ID. Switchboard Menu Add a new menu called Display Reports using the Switchboard Manager. Include menu items to display the Customer List and Customer Order Totals reports, and a menu item to return to the main menu. Add the Display Reports menu to the main menu. 16