Presentation is loading. Please wait.

Presentation is loading. Please wait.

Access and Condition Statements

Similar presentations


Presentation on theme: "Access and Condition Statements"— Presentation transcript:

1 Access and Condition Statements
Please use speaker notes for additional information! This presentation will deal with conditional statements in Access. We will deal with complex conditions involving AND and OR.

2 This shows the data that I have in the table called tablestu
This shows the data that I have in the table called tablestu. The structure is on the next slide.

3 This is the structure of the data
This is the structure of the data. Notice that only gpa and credits are numbers. The gpa is single to allow for decimal places and the credits is an integer. Note also that the key is idno.

4 I am asking for all records where the major = “CI”
I am asking for all records where the major = “CI”. Note that this can be written as =“CI” but Access decides you do not need the = and eliminates it. Essentially equal is the default. This shows the simple query of asking for all CI majors. There are 14 records in the table. Seven of these records have the major CI. As a result of this query, those records are shown.

5 Problem: I want to display the record for all students that have a major = “CI”, a state = “MA” and credits > 15. Logic flowchart: Pseudocode: if major = “CI” then if state = “MA” then if credits > 15 then display record endif major=“CI” No Yes state=“MA” No Yes credits > 15 No Yes This shows a problem, the logic flowchart showing the solution and the pseudocode showing the logic to solve the problem. The solution in Access is shown on the next slide. This is the AND structure. In this example there are three things that must be true, it could have been two or four etc. Display in list

6 This shows asking for all records where major = "CI" and state = "MA" and credits is > 15. Note that CI and MA are in quotes because they are text. 15 is a numeric so it is not in quotes.

7 Problem: I want to display the record for all students that have a major = “CI” or a major of “BU”.
No Yes Pseudocode: if major = “CI” then display record else if major = “BU” then endif Display in list major=“BU” No Yes Display in list This shows the problem, the logic flowchart and the pseudocode for a simple OR structure. One or the other of these has to be true. It does not matter which is true. The Access for this query is shown on the next slide.

8 In this example I want major to be either “CI” OR “BI”
In this example I want major to be either “CI” OR “BI”. Notice that I have the first thing under criteria and the second under OR. Only one record does not meet the criteria - 13 out of the 14 records are either CI or BU majors. Note that when I want an AND relationship the criteria are on the same line. When I want an OR relationship the criteria are on different lines.

9 Problem: I want to display the record for all students that have a major = “CI”AND either the gpa is greater than 3.5 or the credits is > 30. Flowchart: Pseudocode: if major = “CI” then if gpa > 3.5 then display record else if credits > 30 then endif major=“CI” No Yes gpa > 3.5 No Yes credits > 30 Display in list Yes No Display in list If major is = to “CI” then I can continue and ask the other questions. If major is not = “CI” then I am done. Once I have established that major is equal to “CI” then I have a standard OR where I am asking whether the gpa > 3.5 OR credits > 30. The structure is that the first question needs to be true and then either of the remaining questions have to be true. This shows the flowchart and pseudocode for a structure that uses both AND and OR.

10 In many languages this would be written as:
Access requires that you repeat the “CI” on both lines. Essentially, Access makes you ask the question as is major = “CI” and gpa > 3.5 OR is major = “CI” and credits > 30. This is because of the limitations of the user friendly query in Access. In many languages this would be written as: if major=“CI” and (gpa > 3.5 or credits > 30) As you will see, logic dictates that ANDs get resolved before ORs. This means that things around the AND get processed together. In this example, I want the OR to group two things together. I can change the order of operations by using the parenthesis to group the OR conditions so it read major = “CI” and either of the other conditions. This shows the results. Notice that all people have CI and that two of them are there because the gpa is greater than 3.5 and one of them is there because credits is greater than 30. Note that Access does provide a more extended way to do queries using SQL.


Download ppt "Access and Condition Statements"

Similar presentations


Ads by Google