[ Team LiB ] |
Creating Calculated FieldsOne of the rules of data normalization is that you shouldn't include the results of calculations in a database. You can output the results of calculations by building those calculations into queries, and you can display the results of the calculations on forms and reports by making the query the foundation for a form or report. You can also add to forms and reports controls that contain the calculations you want. In certain cases, this can improve performance. The columns of a query result can hold the result of any valid expression. This makes queries extremely powerful. For example, you could enter the following expression: Left([FirstName],1) & "." & Left([LastName],1) & "." This expression would give you the first character of the first name, followed by a period, the first character of the last name, and another period. An even simpler expression would be this one: [UnitPrice]*[Quantity] This calculation would simply multiply the UnitPrice field by the Quantity field. In both cases, Access would automatically name the resulting expression. For example, Figure 10.19 shows the calculation that results from concatenating the first and last initials. Notice in the figure that Access gives the expression a name (often referred to as an alias). To give the expression a name, such as Initials, you must enter it as follows: Initials:Left([FirstName],1) & "." & Left([LastName],1) & "." Figure 10.19. The result of using the expression Initials:Left([FirstName],1) & "." & Left([LastName],1) & "." in a query.The text preceding the colon is the name of the expression—in this case, Initials. If you don't explicitly give an expression a name, the name defaults to Expr1.
Task: Adding a Calculation to a Query
|
[ Team LiB ] |