Presentation is loading. Please wait.

Presentation is loading. Please wait.

Examining data using Microsoft Access Queries Using Criteria and Calculations SESSION 3.2 This section covers specifying an exact match condition in a.

Similar presentations


Presentation on theme: "Examining data using Microsoft Access Queries Using Criteria and Calculations SESSION 3.2 This section covers specifying an exact match condition in a."— Presentation transcript:

1 Examining data using Microsoft Access Queries Using Criteria and Calculations SESSION 3.2 This section covers specifying an exact match condition in a query, changing a datasheets appearance, using a comparison operator and “And / Or” logical operators.

2 Before we continue! Let’s stop for a moment to consider a possible hazard that might take place if we are not careful.

3 Unlike many other database programs, Microsoft Access has two kinds of queries. The 1st is the Select query, The second is called an Action query.

4 In the past, the primary purpose, and in most cases the only purpose of a query was to “Select” specific records for viewing. In Access, this type of query is referred to as a “Select Query”

5 Access, on the other hand has a second type of query, called an “Action Query”. An Action Query is a query that adds, changes, or deletes multiple table records at one time.

6 We could, for example, create an “Action Query” that will delete selected records. To cause this action to occur, we would “RUN” the query.

7 The purpose of a Select query is to “VIEW” the datasheet with just the records selected by the criteria used. To cause this to happen we could also “RUN” the query. To test an Action query, we will need to “VIEW” it’s datasheet before we actually “RUN” the query.

8 If we get into the habit of “Running” select queries to “VIEW” the datasheet, when we want to test an “ACTION” query to see if it will return the proper data, we might by accident, “RUN” the query thinking that we will see it’s datasheet.

9 The “ounce of prevention” to use here, in order to prevent the need for a “pound of cure” would be to use the “VIEW” method whenever we want to see the datasheet instead of “Running” the query.

10 Use the “RUN” method only when you need to cause an Action query to do the action that it was designed for. To test an Action query (view the Datasheet) before running it, use the “VIEW” method, and to view the datasheet of a Select query, also use the “VIEW” method.

11 In this session we will look at defining record selection by using criteria and creating calculated fields in Select queries. The Criteria Row

12 Just as you can display selected fields from a table in a query’s datasheet, you can display selected records. To tell Access which records you want to select, you can specify a condition as part of a query. A condition is a criterion, or rule, that determines which records are selected. To define a condition for a field, you place the condition in the field’s Criteria text box in the design grid.

13 A condition usually consists of an operator, often a comparison operator, and a value. A comparison operator asks Access to compare the values of a database field to the condition value and to select all the records for which the relationship is true.

14 For example, the condition >1000.00 for the InvoiceAmt field selects all records in the Order table having InvoiceAmt field values greater than 1000.00

15 Operator Meaning = Equal to (optional, default operator) Example =“Hall” Operator Meaning < Less than Example <#1/1/99#

16 Operator Meaning < = Less than or equal to Example <=100 Operator Meaning > Greater than Example >100

17 Operator Meaning > = Greater than or equal to Example >=100 Operator Meaning Not equal to Example <>”Hall”

18 Operator Meaning Between … And... between two values (inclusive) Example Between 50 And 100 Operator Meaning IN () in a list of values Example In (“Hall”, “Seeger”)

19 Operator Meaning Like matches a pattern that includes wildcards Example Like “706*” These operators will be placed on the criteria row below, in the design grid.

20 It’s worthwhile to mention here that you can use multiple selection criteria in queries. In other words, you can place specific criteria in as many fields as you have in the query. We will see an example of this in today’s exercise.

21 Another important function that you will use queries for is to create new fields by calculating values. These calculations can be either numeric or can manipulate text.

22 An example of manipulating text would be to combine the City, State and Zip fields into one field or to extract the Area Code from the phone # field and place it in a separate field.

23 To perform a calculation, you define an expression containing a combination of database fields, constants, and operators. To perform a calculation in a Query, you add a calculated field to the query. A calculated field is a field that displays the results of an expression. A calculated field appears in a query datasheet but does not exist in a table.

24 Field Name Expression Separator An Expression in a query is made up of three components: Calculated Field

25 When you “VIEW” or “RUN” a query that contains a calculated field, Access evaluates the expression defined by the calculated field and displays the resulting value in the datasheet.

26 Microsoft Access will calculate an expression in the following order: 1. Parentheses 2. Exponents (to power of) 3. Multiplication 4. Division 5. Addition 6. Subtraction

27 You can remember this with the phrase: Please Excuse My Dear Aunt Sally. 1. Parentheses 2. Exponents (to power of) 3. Multiplication 4. Division 5. Addition 6. Subtraction

28 Another function of a query is to calculate statistical information, such as totals, counts, and averages. Aggregate functions in a query perform arithmetic operations on selected records. Queries that perform this kind of operation are sometimes referred to as Aggregate Queries.

29 To create an aggregate query you can click on the Aggregate button on the toolbar. When you create an Aggregate Query a new row will appear in the Design Grid.

30 You can select the function that you want Access to perform by clicking on the selection arrow in the Totals row in the column that you want the function performed in. A list of available functions will appear.

31 An alternative method of creating an aggregate query is to use “View” from the Menu Bar and clicking on “Totals”

32 Finally in today’s session we will look at Lookup fields. Lookup Fields are created by changing the data type in the table to “Lookup”. This can be done in two ways: 1) Manually and 2) with a wizard.

33 A lookup field provides the user when entering data with a selection box to choose the data that he or she wants to enter into a field.

34 The selection box will use either another table that contains the appropriate data or you can enter the data into the properties of the field in a value list.

35 To manually create a lookup field, first select the field and then click on the lookup tab in the field properties section.

36 Select Combo Box Select Table/Query or Value List to enter your own values.

37 If you select Table/Query above select the table or query name to use here. If you select value list, type the values in here.

38 Select the column in the table or query or value list that contains the data you want inserted into your field when you make your selection.

39 Tell Access how many columns you want to appear in your selection list when you activate the lookup box.

40 Tell Access whether or not you want column heads to appear when you activate your lookup box. (Yes or No)

41 Tell Access how wide each column will be in your lookup box.

42 Tell Access how many rows will appear in your lookup box. If there are more rows in the source of data a scroll bar will appear.

43 Tell Access how wide the lookup box will be. This is generally the total of the column widths above.

44 And finally, indicate that you want the user to either be able to type anything in this field or just what appears in the list.

45 Page AC 3.37 Quick Check Review

46 Let’s take a few moments to break up into discussion groups. Each group will discuss the quick check questions on page AC 3.37 in your books. We will then review the answers at the end of the discussion.

47 Quick Check Review Session 3.2 1) A(n) ________ is a criterion, or rule, that determines which records are selected for a query datasheet.

48 Quick Check Review Session 3.2 2) In the design grid, where do you place the conditions for two different fields when you use the And logical operator? The Or logical operator?

49 Quick Check Review Session 3.2 3) To perform a calculation in a query, you define a(n) ___________ containing a combination of database fields, constants, and operators.

50 Quick Check Review Session 3.2 4) How does a calculated field differ from a table field?

51 Quick Check Review Session 3.2 5) What is an aggregate function?

52 Quick Check Review Session 3.2 6) The ________ operator divides selected records into groups based on the values in a field. And Finally!

53 As we saw in the last session, Barbara Hennessey and her office staff need to track information about all the orders for which bills have been paid. For Barbara’s request you will need to create a query that will display only those records in the Order Table with the value of 1/15/99 in the BillingDate field.

54 Both Barbara and Leonard are beginning to see the value of what this program has and now have begun to request much more information. As a result, the staff at Valle Coffee have once again requested your assistance,

55 At a recent company meeting, Leonard Valle and other Valle Coffee employees discussed the importance of regularly monitoring the business activity of the company’s restaurant customers. For example, Kim Carpenter and her marketing staff track customer activity to develop new strategies for promoting Valle Coffee Products.

56 Barbara Hennessey and her office staff need to track information about all the orders for which bills were sent out on a specific date so that they can determine better the bills have been paid.

57 In addition, Leonard is interested in analyzing the payment history of restaurant customers to determine which customers pay their invoices in a timely manner, which customers have higher invoice amounts, and so on.

58 All of these informational needs can be satisfied by queries that retrieve information from the Restaurant database.

59 You have been requested to help the people at Valle Coffee with creating queries that will answer their questions. Your assignment today is to do the class exercises starting on Page AC 3.19 through page AC 3.37. And Page AC 5.04 through page AC 5.08


Download ppt "Examining data using Microsoft Access Queries Using Criteria and Calculations SESSION 3.2 This section covers specifying an exact match condition in a."

Similar presentations


Ads by Google