Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Computer Science АС (ГСФ) / CS Work at practical classes / 9 Work with package MS Office.doc
Скачиваний:
12
Добавлен:
18.02.2016
Размер:
328.19 Кб
Скачать

To Do: Work with Complex Queries

To complete the query, follow these steps:

  1. Click the first column's row labeled Table and select the table that contains the resulting query's first field. If you want the query's data subset to start with a field from the Tenants table, for example, you select Tenants from the drop-down list.

  2. Click the first column's row labeled Field and select the field that you want to place first in the resulting data subset. You might select Customers from the list, for example.

  3. If you want to sort the resulting query's subset based on the first field, select either Ascending or Descending from the row labeled Sort. You don't have to sort on the first field that you add to the query; you can sort on any field that you add. The query sorts all the resulting data based on the value of the field by which you sort. If you sort on two or more fields, Access sorts the data in the leftmost Sort column first.

  4. Leave the Show option checked if you want the field to appear in the resulting query's data subset. Generally, you want the field to appear. If you want to sort the subset on a field but not send that sort field to the resulting extracted subset, uncheck the Show option for that field.

  5. Click the first column's row labeled Criteria and enter a criterion. If you type a value, such as JJ1, Access extracts only those records with a field containing JJ1. You can continue adding criteria values beneath the first one. You can type the values JJ1,BR1, BR2, and BE1 for five rows of criteria (still in the first column). It is like asking Access to extract only those tenants whose Tenant ID is JJ1, BR1, BR2, or BE1, for example. If the field is a text-data type, Access encloses the criteria in quotation marks (like the fields shown in Figure 19.7). Access encloses dates inside pound signs (#1/6/1898#, for example) if you enter dates in the criteria.

Figure 19.7 This query must match several criteria values for Customer ID.

  1. It gets fun here. Instead of selecting the field from the second column's drop-down list labeled Field, drag the field name from a table in the upper half of the Query Design view (such as the Order Date field in the Orders table). Access automatically fills in the table and field name in the second column of the query! (You might also double-click a field name from the table in the upper portion of the Query Design view to use that field name in the query.)

  2. Enter the selection criteria for the new field. The criteria indicate exactly how you want to pull records from the table. If you want to extract all the records (all that fall within the criteria of the first field that you have entered), leave the second field's criteria blank. You can further limit the extraction by entering an additional criterion for the second field. Suppose that you not only want customers with the IDs listed in the first criteria, but you also want to limit the selection to any of those five who have an order date of January 6, 2005. You enter #1/6/2005# for the criteria.

  3. Continue adding fields that you want to appear in the resulting query. When you execute your query, these fields appear in the resulting table.

As you work with the query, you might want to add more tables. Add the tables in the Query Design view by selecting Query, Show Table. Add as many tables (or queries) as you prefer to the query from within the Query Design view, but remember that the tables and queries must relate somehow. Remove a table or query from the Query Design view by right-clicking the table name and selecting Remove Table.

Note

You can use all the cut, copy, and paste methods that you learned earlier in the book for the query-extraction fields. You can move a field from one location to another by selecting, cutting, and pasting it, for example. You can also resize column widths by dragging the field column edges, and you can change any value by clicking that value in the Query Design view.

If you really want to get fancy, use the relational operators in Table 19.1 to add to your extraction power.

Соседние файлы в папке CS Work at practical classes