1 / 7

BUILDING CONDITIONS II

BUILDING CONDITIONS II. Using an IF statement if [type] = “teacher” [rate] = 10/100 else if [type] = “student” [rate] = 20/100 else if [type] = “handicapped” [rate] = 25/100 else --> means type is none of these [rate] = 0 endif endif endif.

valentine
Télécharger la présentation

BUILDING CONDITIONS II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. BUILDING CONDITIONS II Using an IF statement if [type] = “teacher” [rate] = 10/100 else if [type] = “student” [rate] = 20/100 else if [type] = “handicapped” [rate] = 25/100 else --> means type is none of these [rate] = 0 endif endif endif EXAMPLE: We want to display the discount rate on train tickets according to the customer type: 10% for teachers 20% for students 25% for handicapped no discount for others IF STATEMENTS OR LOOKUP TABLES? Sometimes, we have a set of conditions which make a large set of nested IF statements. In this case, a LOOKUP table would be more practical. N. Fenmen - CAA292 Database Applications for Business - 2003 - 2004 Spring

  2. Using an IF statement if [type] = “teacher” [rate] = 10/100 else if [type] = “student” [rate] = 20/100 else if [type] = “handicapped” [rate] = 25/100 else --> means type is none of these [rate] = 0 endif endif endif BUILDING CONDITIONS II 10% for teachers 20% for students 25% for handicapped no discount for others Using the IIf statement in Access for the textbox [rate]: IIf([type] = “teacher”; 10/100; IIf ([type] =“student”; 20/100; IIf ([type] = “handicapped”; 25/100; 0))) N. Fenmen - CAA292 Database Applications for Business - 2003 - 2004 Spring

  3. Using an IF statement if [type] = “teacher” [rate] = 10/100 else if [type] = “student” [rate] = 20/100 else if [type] = “handicapped” [rate] = 25/100 else --> means type is none of these [rate] = 0 endif endif endif BUILDING CONDITIONS II Using a CASE statement instead of many nested IF statements case [type] = “teacher”[rate] = 10/100case [type] = “student”[rate] = 20/100case if [type] = “handicapped”[rate] = 25/100case if [type] = “others”[rate] = 0 10% for teachers 20% for students 25% for handicapped no discount for others N. Fenmen - CAA292 Database Applications for Business - 2003 - 2004 Spring

  4. Using a CASE statement instead of many nested IF statements case [type] = “teacher”[rate] = 10/100case [type] = “student”[rate] = 20/100case if [type] = “handicapped”[rate] = 25/100case if [type] = “others”[rate] = 0 Transfer this into a Lookup Table Make a table with two fields (two columns) showing the [type] and the [rate] for each type: BUILDING CONDITIONS II typerate teacher 0,10 student 0,20 handicapped 0,25 others 0 What is the discount rate for teachers? DLookup(what to bring; where to search; condition) bring the rate; search in the customers table; the [type] in the table = the [type] of this customer N. Fenmen - CAA292 Database Applications for Business - 2003 - 2004 Spring

  5. Our Lookup Table (Let’s say its name is customers) What is the discount rate for teachers? We use a lookup function which finds the answer in our lookup table. BUILDING CONDITIONS II typerate teacher 0,10 student 0,20 handicapped 0,25 others 0 DLookup(what to bring; where to search; condition) In the customers table [rate] The [type] in the customers table matches (is equal to) [type] of the customer on the form N. Fenmen - CAA292 Database Applications for Business - 2003 - 2004 Spring

  6. DLookup(what to bring; where to search; condition) BUILDING CONDITIONS II In the customers table The [type] in the customers table matches the [type] of the customer on the form (let’s say the form is train_form) [rate] DLookup(“[rate]”; “customers”; “[type]=” &Forms![train_form]![type]) N. Fenmen - CAA292 Database Applications for Business - 2003 - 2004 Spring

  7. Some examples where a LOOKUP table is much better than nested IF statements: There is a price list for train tickets, depending on the destination. We want to match the destination, and learn the price. We want to do some statistics with the population of each city. We want to match the city name and get the population. The income tax rate for employees depends on their yearly gross salary amount. We want to give an employees gross salary and get the tax rate. BUILDING CONDITIONS II N. Fenmen - CAA292 Database Applications for Business - 2003 - 2004 Spring

More Related