100 likes | 192 Views
Access and Condition Statements. Please use speaker notes for additional information!. 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.
E N D
Access and Condition Statements Please use speaker notes for additional information!
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.
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 endif endif major=“CI” No Yes state=“MA” No Yes credits > 15 No Yes Display in list
Problem: I want to display the record for all students that have a major = “CI” or a major of “BU”. major=“CI” No Yes Pseudocode: if major = “CI” then display record else if major = “BU” then display record endif endif Display in list major=“BU” No Yes Display in list
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.
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 display record endif endif 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.
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.