Presentation is loading. Please wait.

Presentation is loading. Please wait.

Finish ing the logic flowc harts from week 3.. if invcd = “A” and (amtfst > 500 or amtsnd > 200) move “OKAY” to msg end if With the parenthesis, invcd.

Similar presentations


Presentation on theme: "Finish ing the logic flowc harts from week 3.. if invcd = “A” and (amtfst > 500 or amtsnd > 200) move “OKAY” to msg end if With the parenthesis, invcd."— Presentation transcript:

1 Finish ing the logic flowc harts from week 3.

2 if invcd = “A” and (amtfst > 500 or amtsnd > 200) move “OKAY” to msg end if With the parenthesis, invcd has to be A and either of the other things have to be true. Without parenthesis, the things around the AND get resolved together and the criteria after the OR stands alone. The logic rule is that ANDs are resolved before ORs meaning that the conditions on either side of the AND are grouped.

3 The pseudocode can be written with one if as shown previously, 3 separate if statements or two if statements as shown next.

4 This shows one if statement asking about invcd = "A" and then a second if statement that asks the either or question only if the code is A.

5 Without the parenthesis the amtsnd > 200 stands alone so I need to ask it if I get a no to either of the questions in the group.

6 For easier coding, I can ask the standalone question first.

7 In this case, I have to ask each question separately because I have different actions.

8 Now I am starting to look at SQL or sequel as it can also be called. SQL is the query language that is really executed when you put code into the user interface as we have been doing. You can also write SQL directly. Here I went into the user interface and picked the table I wanted to use. Then I went over to the view icon and hit the arrow beneath it and selected SQL view. Note that I am showing the code in notepad (I cut and pasted) so it is more readable - that has nothing to do with Access. The select * means show all fields. The from tells what table to use. Note that SQL ends with a semi-colon.

9

10 If I want to only show specific fields, I can list them. Be careful to only use field names defined in the table you are using. In this case, the table is stu.

11 This is what it would have looked like if I had done it in the user interface.

12 Now I am adding criteria. I only want to see the records where gpa is greater than 3. This is like entering > 3 below the gpa column in the user interface.

13 When you do comparisons whether in SQL or the user interface, you should compare things of the same type. Compare two numbers or two text fields. In this case gpa was defined in my table as a number and I am comparing to the number 3.

14 Now I am doing an AND where both criteria have to be true. Note also that major was defined as text and CI is in quotes.

15 This shows the results. All records are CI majors with gpa > 3.

16

17 Now I have change to an OR so one of these has to be true.

18 Now I want to test for major = "CI" and one of the other criteria must be true. These other two criteria are in an OR relationship.

19

20 Here I did not put in the parenthesis so I would get the wrong results. I need to add the parenthesis to get the situation where it has to be a CI major and then either of the other criteria. SELECT stuid, stuname, major, numcr, gpa FROM stu WHERE major = "CI" and (numcr > 20 or gpa > 3);

21 This shows the results once I put in the parenthesis.

22 Now I am showing the user interface where CI does not have to be true. I can have either CI and numcr > 18 OR gpa > 3.2

23 This is the way Microsoft writes it. Note the stu.stuid where the table name is put in before the field. I have table name dot field name. Also note the many many parenthesis.

24 This is the simplified version.

25


Download ppt "Finish ing the logic flowc harts from week 3.. if invcd = “A” and (amtfst > 500 or amtsnd > 200) move “OKAY” to msg end if With the parenthesis, invcd."

Similar presentations


Ads by Google