Page 5 of 10PREVNEXT

Queries IV: Use functions and calculated fields in your queries

Operator precedence affects your results

Parentheses can mean the difference between fact and fiction.

You override normal operator precedence by using parentheses around the part of a formula you want Access to calculate first. For example, look at the formula in the picture. If you set the Quantity value to 500, the CurrentPrice value to 40, and the StartPrice value to 35, then with parentheses in place, Access performs the subtraction first and the result is 2,500. Without parentheses, Access performs the multiplication first and the result is 19,965. That's a huge difference, and an error like that can cause serious problems.

So keep these rules in mind:

  • If you have multiple parentheses nested inside each other, Access works from the inside out.
  • If you have multiple operators at the same level, Access evaluates them from left to right.

You'll get a chance to use parentheses and operator precedence during the practice, and the Quick Reference Card gives you more information about them.

Page 5 of 10PREVNEXT