320 likes | 514 Views
Lesson 10 – Designing Advanced Queries. Lesson Objectives. Create and use select queries. Create and use summary queries. Work with summary query options. Create and use a parameter query. Create and use action queries. Creating Select Queries. Exercises Create a Query from a Filter
E N D
Lesson Objectives • Create and use select queries. • Create and use summary queries. • Work with summary query options. • Create and use a parameter query. • Create and use action queries.
Creating Select Queries Exercises • Create a Query from a Filter • Create a Subquery
Create a Query from a Filter • Convert a datasheet filter to a query
Create a Subquery • Queries create a dynaset using recordsets • Subqueries create a dynaset using other queries • Can help reduce complexity • Can increase speed to create the dynaset
Creating and Using Summary Queries Exercises • Create a Summary Query Using a Wizard • Create a Summary Query in Design View
Create a Summary Query Using a Wizard • Summary queries show aggregate values for a recordset
Create a Summary Query in Design View • Summary queries require the Total row • By default, all fields are set to “Group By” • Aggregate Functions • Sum & Avg functions • Numeric data types • Count function • Any data type
Working with Summary Query Options Exercises • Use Aggregate Functions in a Query • Use the Month Function in a Query • Use the MonthName Function in a Query • Use the Year Function in a Query • Enter a Calculation in a Query • Create a Summary Query
Use Aggregate Functions in a Query • Summarized data can be used to forecast trends
Use the Month Function in a Query • The Month Function extracts the numeric value of each month from a data value
Use the MonthName Function in a Query • The MonthName Function extracts the name of each month from a data value
Use the Year Function in a Query • The Year Function extracts the numeric value of year from a data value
Enter a Calculation in a Query • Subtracting two dates will give you the duration between the two dates
Create a Summary Query • Summary queries can contain many data calculations
Creating and Using a Parameter Query Exercises • Run a Parameter Query • Create a Parameter Query • Set Data Types in a Parameter Query • Use Multiple Criteria in a Parameter Query • Use a Parameter Query with Wildcards • Use a Parameter Query with a Report
Run a Parameter Query • Parameter queries prompt the user to type a value • The typed value is then used as a criterion
Create a Parameter Query • Create a select query • Add a criterion and test • Replace the criterion with a prompt with square brackets
Set Data Types in a Parameter Query • A parameter query assumes the data type of the parameter is Variant • Variant data types are inefficient • If the criterion is expecting a date, the parameter should be set to Date/Time data type
Use Multiple Criteria in a Parameter Query • Queries can have more than one criterion • Queries can have more than one parameter
Use Multiple Criteria in a Parameter Query • Parameters work the same as criteria when creating “AND” and “OR” queries
Use a Parameter Query with Wildcards • To use wildcards in a criterion or parameter you must use the keyword “LIKE”
Use a Parameter Query with a Report • Reports are based on recordsets • If the recordset contains a parameter, one report can show data based on the parameter value
Creating and Using Action Queries Exercises • Create an Update Query • Edit an Update Query • Create a Make-Table Query • Create a Delete Query • Create an Append Query
Create an Update Query • Update queries can make global changes to a group of fields
Edit an Update Query • This type of query is normally used only one time • Can be saved and edited
Create a Make-Table Query • Used to copy data from one recordset to a new table • Can have criteria
Create a Delete Query • Used to delete records from a recordset based on a criterion
Create an Append Query • Used to join records from different recordsets
Lesson 10 Summary • Queries can be categorized as select queries, summary queries, parameter queries, and action queries. • A select query locates data from one or more tables and displays the dynaset in a defined order. • A filter can be used to create a select query. • When you use a query within a query, you create a subquery. • Summary queries are select queries that display summarized rather than individualized data. • For each summarized field in a query, Access creates a caption on the basis of the function and the name of the field. • Aggregate functions summarize large or complex data.
Lesson 10 Summary • The Month function extracts the numeric value of the month from a date/time value. • The MonthName function extracts the name of the month from a date/time value. • The Year function extracts the numeric value of the year from a date/time value. • The numeric values of two dates can be subtracted to display a numeric value. • A parameter query prompts the user for criteria each time it runs. When you create a parameter query, you must first choose the field or fields on which comparisons are to be made. • Wildcards can only be used with text and numeric fields.
Lesson 10 Summary • When you create a parameter, Access sets the format to the default variant data type. • If you place two parameters on the same criteria row, both criteria must match for the record to be included in the dynaset. If you place parameters on separate rows, either criterion must match for the record to be included in the dynaset. • A make-table query is an action query that creates a new table. A delete query is an action query that deletes a group of records. An append query is an action query that adds a group of records to the end of a table. An update query is an action query that makes global changes to a group of records.