Creating Queries with Comparison and Logical Operators

Creating Queries with Comparison and Logical Operators

You can use the Expression Builder to create more complicated queries. For example, you can use comparison operators , such as >, <, or =, to compare field values to constants and other field values. For example, you can use the greater-than operator (>) to create a query that retrieves records in which more than 1 toy is ordered. You can also use logical operators to create criteria combining several expressions. For example, you can use the AND operator to retrieve records in which the number of toys ordered is greater than 1 AND less than 5. You can also use logical operators to negate expressions. For example, you could run a query that retrieves toy records that are NOT infant toys.

Use a Comparison Operator

graphics/1_icon.jpg

Display the query in Design View, and then click the Criteria box for the field.

graphics/2_icon.jpg

Click the Build button on the Query Design toolbar.

graphics/3_icon.jpg Click the appropriate comparison operator button.

To see additional comparison operators, click the Operators folder, click Comparison, and then choose the comparison operator you want from the list on the right.

graphics/4_icon.jpg

Enter a value or click a field whose value you want to compare.

graphics/5_icon.jpg

Click OK.

graphics/6_icon.jpg

Click the Run button on the Query Design toolbar.

graphics/06inf12.jpg

Use a Logical Operator

graphics/1_icon.jpg

Display the query in Design view, and then click the Criteria box.

graphics/2_icon.jpg

Click the Build button on the Query Design toolbar.

graphics/3_icon.jpg Click the appropriate logical operator button.

To see additional comparison operators, click the Operators folder, click Logical, and then choose the logical operator you want from the list on the right.

graphics/4_icon.jpg

Enter any values needed to complete the expression.

graphics/5_icon.jpg

Click OK.

graphics/6_icon.jpg

Click the Run button on the Query Design toolbar.

graphics/06inf13.jpg

Did You Know?

You can fine-tune selection criteria . To fine-tune your selection criteria, combine logical and comparison operators in the same expression.

You can compare one field with another . To create an expression that compares one field with another, use the Expression Builder and look within the Tables folder to locate the table and field of interest. Double-click the field name to add it to the expression. The expression should contain the table name and field name in brackets, separated by an exclamation point. For example, to choose records where the value of the OnOrder field in the Orders table is greater than the value of the InStock field, the expression is: [Orders]![OnOrder]>[Orders]![InStock] .




Show Me Microsoft Office Access 2003
Show Me Microsoft Office Access 2003
ISBN: 0789730049
EAN: 2147483647
Year: 2002
Pages: 318

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net