26
Microsoft Office 2007- Microsoft Office 2007- Illustrated Illustrated Building and Using Building and Using Queries Queries

Microsoft Office 2007- Illustrated Building and Using Queries

Embed Size (px)

Citation preview

Page 1: Microsoft Office 2007- Illustrated Building and Using Queries

Microsoft Office 2007- IllustratedMicrosoft Office 2007- Illustrated

Building and Using QueriesBuilding and Using Queries

Page 2: Microsoft Office 2007- Illustrated Building and Using Queries

ObjectivesObjectives

• Create a queryCreate a query

• Use Query Design ViewUse Query Design View

• Modify queriesModify queries

• Sort and find dataSort and find data

(continued)(continued)

Microsoft Office 2007-Illustrated

Page 3: Microsoft Office 2007- Illustrated Building and Using Queries

Objectives Objectives

• Filter dataFilter data

• Apply AND criteriaApply AND criteria

• Apply OR criteriaApply OR criteria

• Format a datasheetFormat a datasheet

Microsoft Office 2007-Illustrated

Page 4: Microsoft Office 2007- Illustrated Building and Using Queries

Creating a QueryCreating a Query

• A query allows you to “ask” for only A query allows you to “ask” for only the information you want vs. the information you want vs. navigating through all the fields and navigating through all the fields and records of large tablesrecords of large tables

• You can enter, edit and navigate data You can enter, edit and navigate data in a query datasheet just like a table in a query datasheet just like a table datasheetdatasheet

• Query = logical view of the dataQuery = logical view of the data

Microsoft Office 2007-Illustrated

Page 5: Microsoft Office 2007- Illustrated Building and Using Queries

Creating a QueryCreating a Query

• One way to create a query is by One way to create a query is by using the Simple Query Wizardusing the Simple Query Wizard

• The Wizard asks you questions to The Wizard asks you questions to determine the information you wantdetermine the information you want

Microsoft Office 2007-Illustrated

Page 6: Microsoft Office 2007- Illustrated Building and Using Queries

Simple Query Wizard:Simple Query Wizard:Selecting FieldsSelecting Fields

Microsoft Office 2007-Illustrated

Page 7: Microsoft Office 2007- Illustrated Building and Using Queries

Using Query Design ViewUsing Query Design View

Microsoft Office 2007-Illustrated

• Another way to create a query is by Another way to create a query is by using Query Design Viewusing Query Design View

• You also use Query Design View to You also use Query Design View to edit an existing queryedit an existing query

• Query Design View presents the Query Design View presents the fields you can choose from in Field fields you can choose from in Field ListsLists

Page 8: Microsoft Office 2007- Illustrated Building and Using Queries

Using Query Design ViewUsing Query Design View

Microsoft Office 2007-Illustrated

• If 2 or more related tables are used, If 2 or more related tables are used, their relationship is shown with a their relationship is shown with a join join lineline

Page 9: Microsoft Office 2007- Illustrated Building and Using Queries

Switching Between Query Switching Between Query Design View & Datasheet ViewDesign View & Datasheet View

Microsoft Office 2007-Illustrated

Page 10: Microsoft Office 2007- Illustrated Building and Using Queries

Modifying QueriesModifying Queries

Microsoft Office 2007-Illustrated

• Work in Design ViewWork in Design View

• Upper pane of Design View window Upper pane of Design View window shows field listsshows field lists

• Lower pane of Design View window Lower pane of Design View window is used to add, delete or change the is used to add, delete or change the order of fieldsorder of fields

Page 11: Microsoft Office 2007- Illustrated Building and Using Queries

Modified QueryModified Query

Microsoft Office 2007-Illustrated

Page 12: Microsoft Office 2007- Illustrated Building and Using Queries

Sorting and Finding DataSorting and Finding Data

Microsoft Office 2007-Illustrated

• Works the same way for queries as it Works the same way for queries as it does for tablesdoes for tables

• Data can be sorted by clicking the list Data can be sorted by clicking the list arrow on a datasheet’s column arrow on a datasheet’s column heading, then click a sorting optionheading, then click a sorting option

• Data can also be sorted by using the Data can also be sorted by using the Sort and Find buttons on the Home Sort and Find buttons on the Home tabtab

Page 13: Microsoft Office 2007- Illustrated Building and Using Queries

Sort and Find ButtonsSort and Find Buttons

Microsoft Office 2007-Illustrated

Page 14: Microsoft Office 2007- Illustrated Building and Using Queries

Filtering DataFiltering Data

Microsoft Office 2007-Illustrated

• Filters provide a temporary way to Filters provide a temporary way to display a subset of records that match display a subset of records that match given criteriagiven criteria

• Filters are not used to calculate sums, Filters are not used to calculate sums, averages, counts, etc.averages, counts, etc.

• Filters are removed when the Filters are removed when the datasheet is closeddatasheet is closed

• Filters can, however, be saved as Filters can, however, be saved as queriesqueries

Page 15: Microsoft Office 2007- Illustrated Building and Using Queries

Filtering DataFiltering Data

Microsoft Office 2007-Illustrated

• Filter By Selection: Filtering by a Filter By Selection: Filtering by a given field value. Filters records for given field value. Filters records for an exact match.an exact match.

• Filter By Form: Filters by comparative Filter By Form: Filters by comparative datadata

Page 16: Microsoft Office 2007- Illustrated Building and Using Queries

WildcardsWildcards

Microsoft Office 2007-Illustrated

• Used to search for a pattern; Used to search for a pattern; represents any characterrepresents any character

• Entered as criteriaEntered as criteria

• ? Used to search for a single ? Used to search for a single charactercharacter

• * Used to search for any number of * Used to search for any number of characterscharacters

Page 17: Microsoft Office 2007- Illustrated Building and Using Queries

Applying AND CriteriaApplying AND Criteria

Microsoft Office 2007-Illustrated

• AND criteria means AND criteria means allall criteria must criteria must be true for the record to be selectedbe true for the record to be selected

• Created by entering 2 or more criteria Created by entering 2 or more criteria in the in the samesame Criteria row of the query Criteria row of the query design griddesign grid

Page 18: Microsoft Office 2007- Illustrated Building and Using Queries

Criteria SyntaxCriteria Syntax

Microsoft Office 2007-Illustrated

• Quotation marks (“) around text Quotation marks (“) around text criteria and pound signs (#) around criteria and pound signs (#) around date criteria are date criteria are automaticallyautomatically added added by Accessby Access

• Criteria in Number, Currency, and Criteria in Number, Currency, and Yes/No fields are not surrounded by Yes/No fields are not surrounded by any charactersany characters

Page 19: Microsoft Office 2007- Illustrated Building and Using Queries

Searching for Blank FieldsSearching for Blank Fields

Microsoft Office 2007-Illustrated

• 2 common criteria are 2 common criteria are Is NullIs Null and and Is Is Not NullNot Null

• Is NullIs Null – Finds all records where no – Finds all records where no entry has been madeentry has been made

• Is Not NullIs Not Null – Finds all records where – Finds all records where any entry has been made (even if any entry has been made (even if zero)zero)

Page 20: Microsoft Office 2007- Illustrated Building and Using Queries

Example of AND CriteriaExample of AND Criteria

Microsoft Office 2007-Illustrated

Page 21: Microsoft Office 2007- Illustrated Building and Using Queries

Comparison OperatorsComparison Operators

Microsoft Office 2007-Illustrated

Page 22: Microsoft Office 2007- Illustrated Building and Using Queries

Applying OR CriteriaApplying OR Criteria

Microsoft Office 2007-Illustrated

• OR criteria means OR criteria means any oneany one criterion criterion must be true for the record to be must be true for the record to be selectedselected

• Created by entering 2 or more criteria Created by entering 2 or more criteria on on differentdifferent Criteria rows of the query Criteria rows of the query design griddesign grid

• Also created by entering 2 or more Also created by entering 2 or more criteria in the criteria in the samesame Criteria cell Criteria cell separated by ORseparated by OR

Page 23: Microsoft Office 2007- Illustrated Building and Using Queries

Applying OR CriteriaApplying OR Criteria

Microsoft Office 2007-Illustrated

Page 24: Microsoft Office 2007- Illustrated Building and Using Queries

Formatting a DatasheetFormatting a Datasheet

Microsoft Office 2007-Illustrated

• CanCan: Change font size, font face, : Change font size, font face, colors, gridlinescolors, gridlines

• CannotCannot: Add custom headers, : Add custom headers, footers, images, subtotalsfooters, images, subtotals

Page 25: Microsoft Office 2007- Illustrated Building and Using Queries

Example of Formatted Example of Formatted DatasheetDatasheet

Microsoft Office 2007-Illustrated

Page 26: Microsoft Office 2007- Illustrated Building and Using Queries

SummarySummary

Microsoft Office 2007-Illustrated

• Create queries to answer “questions” Create queries to answer “questions” about your dataabout your data

• Use table and query datasheets to Use table and query datasheets to view, sort, filter, and find dataview, sort, filter, and find data

• AND / OR criteria are used to filter AND / OR criteria are used to filter datadata

• Filters are temporary; queries are Filters are temporary; queries are permanent objectspermanent objects