Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

AIA101.2.Access Queries Accelerated


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
  • Be the first to comment

AIA101.2.Access Queries Accelerated

  1. 1. Microsoft Access Module: Queries P.O. Box 6142 Laguna Niguel, CA 92607 949-489-1472 [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