Microsoft Access Module: Queries P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.d2associates.com [email_add...
Module Hands On <ul><ul><li>Create a simple query </li></ul></ul><ul><ul><li>Create a multi-table query </li></ul></ul><ul...
Creating a Query <ul><li>Activate the Queries tab of the Database window </li></ul><ul><li>Click the New button </li></ul>...
Query Results <ul><li>Results placed in a  dynaset  in a window </li></ul><ul><li>Dynaset can be used like a regular table...
Query Design Window <ul><li>QBE grid  - controls which fields appear in the dynaset </li></ul><ul><li>Parts of the grid </...
Criteria <ul><li>Logical Comparison Operators </li></ul><ul><ul><li><, >, =, =<, >=. <> </li></ul></ul><ul><li>Special Ope...
Like (“Wild Card Matches”) <ul><li>ANSI standard </li></ul><ul><li>Where customer_last_name like “Jo%” </li></ul><ul><li>L...
Create a Simple Query <ul><li>Use Work_Orders table </li></ul><ul><li>Show fields: all except accum </li></ul><ul><li>Sort...
Simple Query  (Find all records with an “S in the description field) Query by Example (QBE) Grid
Joining Tables <ul><li>Tables can be joined for performing a query  </li></ul><ul><ul><li>Must have a common field </li></...
Joining two Tables Double Click table name to add Drag from PK to FK
Create a multi-table query <ul><li>Join Labor and Employees </li></ul><ul><li>Show following fields: all from labor, fname...
Multi-table Query Design
Multi-table Query Results
Calculated Fields <ul><li>Can embed calculations in a query </li></ul><ul><li>Creates a new temporary field which appears ...
Query with Calculated Field (use the builder)
Query with Calculated Field <ul><li>Use qryLaborDetail </li></ul><ul><li>Add a calculated field which shows the cost of a ...
Query with Calculated Field Results
Concatenated Fields <ul><li>Can “add” two character fields together </li></ul><ul><li>Use & operator </li></ul><ul><li>Exa...
Concatenated Fields <ul><li>Create a new labordetail query </li></ul><ul><li>Add a column with the employee’s full name </...
Concatenated Fields Results
Summarizing Columns <ul><li>SQL aggregate functions </li></ul><ul><ul><li>Sum </li></ul></ul><ul><ul><li>Count </li></ul><...
Query with Aggregate
Query with Aggregate <ul><li>Modify qryLaborDetail2 </li></ul><ul><li>Drop work order fields </li></ul><ul><li>Sum the hou...
Query with Aggregate Results
Parameter Queries <ul><li>Accept a variable when run </li></ul>Order No parameter
Parameter Queries <ul><li>Create a parameter query </li></ul><ul><li>Base on qryLaborDetail_3 </li></ul><ul><li>Show all f...
Parameter Query Results
Accelerated Introduction to Access End of Module P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.d2associate...
Upcoming SlideShare
Loading in …5
×

AIA101.2.Access Queries Accelerated

2,037
-1

Published on

Queries module in course Accelerated Introduction to Microsoft Access. Only retrieval is covered in this module. See the Automating Access module for the Action Queries.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,037
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

AIA101.2.Access Queries Accelerated

  1. 1. Microsoft Access Module: Queries P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.d2associates.com [email_address]
  2. 2. Module Hands On <ul><ul><li>Create a simple query </li></ul></ul><ul><ul><li>Create a multi-table query </li></ul></ul><ul><ul><li>Create calculated fields </li></ul></ul><ul><ul><li>Create a summary query </li></ul></ul><ul><ul><li>Concatenate fields </li></ul></ul><ul><ul><li>Create a parameter query </li></ul></ul><ul><li>Students “hands-on”: </li></ul>
  3. 3. Creating a Query <ul><li>Activate the Queries tab of the Database window </li></ul><ul><li>Click the New button </li></ul><ul><li>Select the type of query </li></ul><ul><li>Interact with the dialog boxes </li></ul>
  4. 4. Query Results <ul><li>Results placed in a dynaset in a window </li></ul><ul><li>Dynaset can be used like a regular table </li></ul><ul><ul><li>Most useful when you work with fields from several tables </li></ul></ul><ul><ul><li>Any changes that are made to a dynaset field are also made to the original record </li></ul></ul>
  5. 5. Query Design Window <ul><li>QBE grid - controls which fields appear in the dynaset </li></ul><ul><li>Parts of the grid </li></ul><ul><ul><li>Field - contains the name of the field </li></ul></ul><ul><ul><li>Table - contains the field’s table name </li></ul></ul><ul><ul><li>Sort - controls the order of displayed data </li></ul></ul><ul><ul><li>Show - displays a field in the dynaset </li></ul></ul><ul><ul><li>Criteria - enter a condition to display selected records </li></ul></ul>
  6. 6. Criteria <ul><li>Logical Comparison Operators </li></ul><ul><ul><li><, >, =, =<, >=. <> </li></ul></ul><ul><li>Special Operators </li></ul><ul><ul><li>LIKE </li></ul></ul><ul><ul><li>IS NULL </li></ul></ul><ul><ul><li>BETWEEN </li></ul></ul><ul><ul><li>IN </li></ul></ul><ul><li>Special characters </li></ul><ul><ul><li>[ square brackets around names] </li></ul></ul><ul><ul><li>(parentheses around function arguments) </li></ul></ul><ul><ul><li># pound sign around dates# </li></ul></ul>
  7. 7. Like (“Wild Card Matches”) <ul><li>ANSI standard </li></ul><ul><li>Where customer_last_name like “Jo%” </li></ul><ul><li>Like “Jo_” </li></ul><ul><li>Microsoft Access </li></ul><ul><li>Where customer_last_name like “Jo*” </li></ul><ul><li>Like “Jo?” </li></ul><ul><li>* means match any string of characters; ? means match one character. </li></ul><ul><li>Access actually allow more sophisticated Unix type search patterns as well – see help </li></ul>
  8. 8. Create a Simple Query <ul><li>Use Work_Orders table </li></ul><ul><li>Show fields: all except accum </li></ul><ul><li>Sort by WoNo </li></ul><ul><li>Only records where description contains an “s” </li></ul><ul><li>Save your query as qrySimple </li></ul>
  9. 9. Simple Query (Find all records with an “S in the description field) Query by Example (QBE) Grid
  10. 10. Joining Tables <ul><li>Tables can be joined for performing a query </li></ul><ul><ul><li>Must have a common field </li></ul></ul><ul><ul><li>Linking in QBE grid performed via a drag operation </li></ul></ul><ul><ul><li>Join types: inner, left outer, right outer </li></ul></ul><ul><ul><li>Use show tables dialog to bring up list of tables </li></ul></ul>
  11. 11. Joining two Tables Double Click table name to add Drag from PK to FK
  12. 12. Create a multi-table query <ul><li>Join Labor and Employees </li></ul><ul><li>Show following fields: all from labor, fname, lname and rate from employees </li></ul><ul><li>Sort by empno then wono </li></ul><ul><li>Save your query as qryLaborDetail </li></ul>
  13. 13. Multi-table Query Design
  14. 14. Multi-table Query Results
  15. 15. Calculated Fields <ul><li>Can embed calculations in a query </li></ul><ul><li>Creates a new temporary field which appears in the dynaset </li></ul><ul><li>Store your calculations there </li></ul><ul><li>Can use an expression “builder” to help </li></ul>
  16. 16. Query with Calculated Field (use the builder)
  17. 17. Query with Calculated Field <ul><li>Use qryLaborDetail </li></ul><ul><li>Add a calculated field which shows the cost of a labor ticket </li></ul><ul><li>Save your query as qryLaborDetail_2 </li></ul>
  18. 18. Query with Calculated Field Results
  19. 19. Concatenated Fields <ul><li>Can “add” two character fields together </li></ul><ul><li>Use & operator </li></ul><ul><li>Example: fname & “ “ & lname </li></ul>
  20. 20. Concatenated Fields <ul><li>Create a new labordetail query </li></ul><ul><li>Add a column with the employee’s full name </li></ul><ul><li>This can be used later in reports, etc. </li></ul><ul><li>Save your query as qryLaborDetail_3 </li></ul>
  21. 21. Concatenated Fields Results
  22. 22. Summarizing Columns <ul><li>SQL aggregate functions </li></ul><ul><ul><li>Sum </li></ul></ul><ul><ul><li>Count </li></ul></ul><ul><ul><li>Avg </li></ul></ul><ul><ul><li>Etc. </li></ul></ul><ul><li>Activated by clicking the Total toolbar button </li></ul><ul><li>Adds a Total line to the QBE query grid </li></ul><ul><li>All selected columns must be in group by or an aggregate </li></ul>
  23. 23. Query with Aggregate
  24. 24. Query with Aggregate <ul><li>Modify qryLaborDetail2 </li></ul><ul><li>Drop work order fields </li></ul><ul><li>Sum the hours and cost </li></ul><ul><li>Save your query as qryLaborGrouped </li></ul>
  25. 25. Query with Aggregate Results
  26. 26. Parameter Queries <ul><li>Accept a variable when run </li></ul>Order No parameter
  27. 27. Parameter Queries <ul><li>Create a parameter query </li></ul><ul><li>Base on qryLaborDetail_3 </li></ul><ul><li>Show all fields </li></ul><ul><li>Prompt for order no </li></ul><ul><li>Save as qryParam </li></ul>
  28. 28. Parameter Query Results
  29. 29. Accelerated Introduction to Access End of Module P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 http://www.d2associates.com

×