SESSION 5.1 In this session we will be exploring Pattern Match Queries List-Of-Values Queries, Non-Matching Values in Queries Both the “And” and the “OR” Operators Parameter Queries (or “Prompt Queries”) CrossTab Queries TopValue Queries Microsoft Access 2000 Class #5 The Major Steps of a MicroSoft Access Database Tables Queries Forms Macros Reports Modules On our road map, we are here! Remember, a query is a question you ask about data stored in a database. Pattern Match Queries, List-Of-Values Queries, Non-Matching Values in Queries, Both the “And” and the “OR” Operators and Parameter Queries (or “Prompt Queries”) are all simply normal select queries that use criteria. The Criteria Row Last session we looked at defining record selection by using criteria and creating calculated fields in Select queries. The Criteria Row In this session we will look at specific criteria in Select queries. The Criteria Row Let’s take a quick look at the “Like”, “In”, “Not”, & the “And / Or” comparison operators that we will be using in our class exercise for this session. The “Like” comparison operator (used in pattern matches) selects records by matching field values to a specific pattern that includes one or more wildcard characters - asterisk (*), question mark (?), and the number symbol (#). To show only those records with an area code of 313 you would enter this in the Phone Criteria Row In the previous example we used parentheses ( ) in our criteria expression.. If we had not needed the parentheses we could have simply typed 313* and Access would have inserted the word Like and the quotes for us. The asterisk represents any string of characters, the question mark represents any single character, and the number symbol represents any single digit. Using a pattern match is similar to using an exact match, except that a pattern match includes wildcard characters. A list-of-values match selects records whose value for the selected field matches one of two or more simple condition values. You could accomplish this by including several “Or” conditions in the design grid, but Access also provides the “In” comparison operator that works as a shorthand. The “In” comparison operator allows you to define a condition with two or more values. If a record’s field value matches at least one value from the list of values, Access selects that record for inclusion in the query results. To show all records that contain CustomerNum 123, 135 and 202 you would enter this in the CustomerNum Criteria row A non-matching value selects records whose value for the selected field does not match the simple condition value. You create the selection criterion using the “Not” logical operator. To omit all states that begin with the letter M you would enter this in the State Criteria row You could also type just Not M* and Access would insert the Like and Quotes for you. Let’s talk about something called compound conditions for a moment. Barbara just came in and asked to see a list of all customers in Ohio and Michigan. Notice the word “and” in Barbara’s request. What would happen if we typed “OH” And “MI” in the State Field’s Criteria Row? The result would look something like this, not finding anything. That’s because we have asked Access to show us all records that contain both MI and OH in the same field. To answer Barbara’s question we would have to enter This criteria would return something like You have the option of entering this criteria in two ways Using the second method as shown below Would return only records in Ohio that contain “756” in the Phone field and every record in Michigan. Using the second method as shown below Would return only records in Ohio that contain “756” in the Phone field and only records in Michigan that contain “756” in the Phone field. Hmm?? Lately it seems as though the questions are getting more and more intense! What if ? Barbara especially is beginning to realize that many unsolved mysteries can be solved with this program by using queries. This has been causing Barbara’s Staff a considerable amount of concern. Two things have been happening. First, more and more time has been spent creating queries. Secondly, The number of queries is growing and it’s becoming more and more difficult to keep track of which query is which. There is an answer to this dilemma! The wizards at Microsoft have come up with a very simple solution! The solution is a parameter query! A parameter query is a query that prompts you for criteria when the query is viewed or run. When Access runs the query, it will display a dialog box and prompt you to enter the criteria desired. To create a parameter query, simply enter the text that you want as your prompt in square brackets in the criteria row for the field that you want to set the criteria for. Leonard is interested Can I. get in how much business summaries ? . Valle Coffee is . doing in each . state! He wants . to know the . total sales by . state and by . month. Is the Sun in the Sky? The answer is “YES!”. The solution is “CrossTab Queries”! A Crosstab query performs aggregate (total) function calculations on the values of one database field, and displays the results in a spreadsheet like format. The quickest way to create a crosstab query is to use the Crosstab Query Wizard, which guides you through the steps for creating crosstab queries. A Crosstab query can also display one additional aggregate function value that summarizes each row’s set of values. The crosstab query datasheet below shows the total sales for each month by state and shows a row total. There are 3 other types of select queries that we need to take a quick look at. Find Duplicates Find Unmatched Top Values Finding duplicate records in very large databases can be a very distasteful and tedious task A find duplicates query is a select query that locates duplicate records in a table or query. You can create this type of query using the Find Duplicates Wizard! Finding unmatched records in very large databases can also be a very tedious task A find unmatched query is a select query that locates unmatched records in a related table. For example, if you can not establish referential integrity between the Customer Table and Order Table, you might have a customer # in the order table that does not exist in the customer table. You can create this type of query using the Find Unmatched Query Wizard! The last select query that we will explore is called a Top Values Query Whenever you have a query that displays a large group of records, you can limit the number to a more manageable size by showing just the first 10 records for example. The Top Values property for a query lets you limit the number of records in the query results. For the Top Values property, you enter either an integer (such as 10, to show the first 10 records) or a percent (such as 50%, to show the first half.) The Top Values Query Button can be found on the Query Design Window’s Tool Bar as shown below: Quick Check Review Page AC 5.23 Quick Check Review Let’s take a few moments to break up into discussion groups. Each group will discuss the quick check questions on page AC 5.23 in your books. We will then review the answers at the end of the discussion. Quick Check Review Session 5.1 1) What is a Lookup Wizard field? Quick Check Review Session 5.1 2) What is a subdatasheet? Quick Check Review Session 5.1 3) A(n) ___________ is a predefined format you use to enter data in a field. Quick Check Review Session 5.1 4) Which comparison operator is used to select records based on a specific pattern? Quick Check Review Session 5.1 5) What is the purpose of the asterisk (*) in a pattern match query? Quick Check Review Session 5.1 6) When do you use the In Comparison operator? Quick Check Review Session 5.1 7) How Do you negate a selection criterion? Quick Check Review Session 5.1 8) When do you use a parameter query? Here we go again ! The staff at Valle Coffee have just finished their weekly meeting and as you can expect, there are more questions than ever to be answered! Your task today is to complete the exercises in Tutorial #5 Page AC 5.14 through Page AC 5.23 Please make a note that the disks to use for today’s class are: Tutorial #5 Level 2 Disk1