Source From:http://www.techrepublic.com
Here's one rule of database management that rings true no matter which database software you use: Don't store a value that you can create on the fly when you need it. In other words, you can save disk space by using calculated fields whenever possible.
Let's look at an example. Say you frequently query an Orders table that contains a Quantity field and a Unit Price field, among others. You don't want to store the total price (the quantity times the unit price) for two reasons. First, if someone edits the record and the price or quantity changes, you'll have to recalculate the price and rewrite the new value to disk. Second, it's easier to display the total price on the fly. Creating a calculated field in a query is pretty straightforward:
For instance, you might enter Total Price:[Quantity]*[Unit Price] as shown in Figure A. Be sure to select the Show check box for this calculated field. When you execute the query, Access will display the results of the calculation in the results.
You can perform all sorts of calculations in a query using calculated fields. You can even add criteria to calculated fields. For example, in the above scenario, you could limit the query output to records whose total price is greater than 500 by adding >500 to the Criteria row under the calculated field.
Here's one rule of database management that rings true no matter which database software you use: Don't store a value that you can create on the fly when you need it. In other words, you can save disk space by using calculated fields whenever possible.
Let's look at an example. Say you frequently query an Orders table that contains a Quantity field and a Unit Price field, among others. You don't want to store the total price (the quantity times the unit price) for two reasons. First, if someone edits the record and the price or quantity changes, you'll have to recalculate the price and rewrite the new value to disk. Second, it's easier to display the total price on the fly. Creating a calculated field in a query is pretty straightforward:
- Create a new query in Design view.
- Add at least the Quantity and Unit Price fields.
- Click the Field row of a blank column on the query design grid.
- Type the name of the calculated field, type a colon, and then enter the expression that defines the calculated value.
For instance, you might enter Total Price:[Quantity]*[Unit Price] as shown in Figure A. Be sure to select the Show check box for this calculated field. When you execute the query, Access will display the results of the calculation in the results.
Figure A |
You can perform all sorts of calculations in a query using calculated fields. You can even add criteria to calculated fields. For example, in the above scenario, you could limit the query output to records whose total price is greater than 500 by adding >500 to the Criteria row under the calculated field.
0 comments:
Post a Comment