Download presentation
Presentation is loading. Please wait.
Published byAmberly Pierce Modified over 9 years ago
1
Microsoft Access 2003 - Intro Class 5 Working with Queries
2
2 Queries Vs. Filters CharacteristicsFiltersQueries *Are saved as an object in the database*NoYes Can be used to select a subset of records in a datasheet Yes Can be used to select a subset of fields in a datasheet NoYes Its resulting datasheet can be sued to enter and edit data Yes Its resulting datasheet can be used to sort, filter, and find records Yes Is commonly used as the source of data for a form or report NoYes Can calculate sums, averages, counts and other types of summary statistics across records NoYes Can be used to create calculated fieldsNoYes
3
3 Table Vs. Dynaset The table includes red, blue, and yellow circles. Given a “Red” criteria, the dynaset only has red circles.
4
4 ???Questions??? Let Queries provide the answers! What data is contained in LastName, FirstName and Phone fields of the Employee Table? How many employees work in the Accounting Department of the company? Queries may “answer” questions such as:
5
5 Matching Criteria This group includes women wearing suits. “Suits” is a criterion. This group includes women wearing blue suits. “Blue” and “suits” is a multiple criteria. Suppose our “database” is a ladies business luncheon.
6
6 Queries – Select Queries Combine fields from more than one table Up to 16 tables can be used Criteria – consists of an expression – a combination of symbols & text that produce a result Set a property that establishes a validation rule of sets a default field property Enter a criteria expression Create a calculated field Set a condition for carrying out a macro Construct functions or procedures in VBA Edit an SQL Query
7
7 Creating a Query in Design View In the Database Window, click the option for creating a query in Design View. A Show Table screen will appear where you select the table(s) that you want to include in the query. Once you have added the tables you want, close the Show Table screen. To remove a table from Query Design View, simply click once on the desired table (box), and press the Delete key on the keyboard. To add more tables to Query Design View, click the Show Table button on the toolbar
8
8 A Tour of Query Design View Table that query is based on Desired field(s) to include in query results Table where the field is coming from (useful if using multiple tables in query) Choose whether to sort a field in query results – when sorting by more than one field, query sorts leftmost field first Enter expression to determine what results the query will give – may enter criteria in multiple fields and use “or” row for multiple criteria in same field
9
9 Working with Fields in Design View To add a field to the design grid: Double-click the field OR Drag the desired field to the grid OR Use the drop-down list in the grid To delete a field from the design grid: Move the mouse to the top of the desired grid column until the mouse turns into a black down-pointing arrow, then click the mouse to select the column Press the Delete button on the keyboard
10
10 To Change Properties of a Field in a Query (e.g. to change the format of a field to currency) In the Query Design Grid, right-click the desired field and click the Properties command from the pop-up menu. The screen that appears should read Field Properties, not Query Properties. If not, keep trying, right-clicking right on the field name in the grid. Once in the Field Properties window, set any properties on any tab, then close the screen.
11
11 Comparison Operators OperatorDescriptionExpressionMeaning >Greater than>50Value exceeds 50 >=Greater than or equal to>=50Value is 50 or greater <Less than<50Value is less than 50 <=Less than or equal to<=50Value is 50 or less <>Not equal to<>50Any number except for 50 Between…AndFinds values between two numbers or dates Between #2/2/95# and #2/2/98# Dates between 2/2/95 and 2/2/98, inclusive InFinds a value that is one of a listIn(“IA”,”KS”,”NE”)Value equals IA or KS, or NE NullFinds records that are blankNullNo value has been entered Is Not NullFinds records that are not blankIs Not NullAny value has been entered, even 0 LikeFinds records that match the criteriaLike “A”Value equals A NotFinds records that do not match the criteria (similar to Not equal to <>) Not 2Numbers other than 2
12
12 Calculated Fields in Queries Begin with expression name (what you want to name the new field), followed by a colon : Use square brackets [] around field names if they are to be used Use mathematical operators such as +, -, *, /, as well as () for order of operations Resulting field appears only in the query, not stored in the table
13
13 Expression Guidelines Separate the name of the expression from the actual expression (formula) by a colon Do not include spaces or special characters Use brackets if spaces or special characters are used in the expression Ie: Name:[First Name]&Space(1)&[Last Name] Name:[First Name] & ” “ & [Last Name]
14
14 Calculated Field Syntax Cost: [Quantity]*[Price] The name of calculated field is followed by a colon. Existing field names must be enclosed in square brackets. Operators are placed outside the square brackets.
15
15 Examples of Calculated Fields Total Price:[UnitPrice]*[Quantity] Creates a new field called Total Price that consists of each unit price multiplied by each quantity entry in the table. New Price:[UnitPrice]*1.05 Creates a new field called New Price that calculates the unit price when increased by 5%. New Price:[UnitPrice]+10 Creates a new field called New Price that simply adds $10 to each existing unit price in the table
16
16 This work is licensed under a Creative Commons Attribution- ShareAlike 2.5 License.Creative Commons Attribution- ShareAlike 2.5 License
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.