IF Then Else IF
Printed From: Crystal Reports Book — Forum Name: Technical Questions
Posted By: wsparks — 26 Jun 2008 at 8:31am
Hi,
I'm somewhat new to Crystal Report Writing and I am trying to run an "If then else if" formula to return a different rate depending on the certain value.
Basically I am linking two tables together in the Database expert by a paycodeid and if the paycodeid belongs to a certain GrandPaycodeid specify a different hourly rate.
This is what I have so far, but I am getting a "String is required here" on the second occurance of "If".
If {PAYCAT1MM.GRANDPAYCODEID} = 11001 then {KNX_VIEW_WFCTTL_LABOR.LABORLEV5DSC} Else IF {PAYCAT1MM.GRANDPAYCODEID} = 11002 then 1.1 * {@Base Rate} Else IF {PAYCAT1MM.GRANDPAYCODEID} = 11003 then {@Base Rate}
A paycodeid is assigned to only one of the above GrandPaycodeID's.
Posted By: saoco77 — 26 Jun 2008 at 9:29am
It looks like your first if statement is returning a string while your second and third if statements are returning a numeric value.
In crystal a formula can't return two different data types. Try:
totext(1.1 * {@Base Rate})
Hope this helps.
Sarah
Posted By: wsparks — 26 Jun 2008 at 10:57am
Thanks, that works, although I reversed it and put a tonumber on the first line. Now I just need to figure out why once I add the formula to my report it no longer returns data.
Posted By: wsparks — 26 Jun 2008 at 11:19am
I figured out why its not returning any data, I just need to figure out a solution.
While my Paycodeid only exists in one of the three grandpaycodes when I started this report and grandpaycode of ALL was made, so I added the new GrandPaycode to the formula to see if it would return a rate and it did.
Can I make the If Then Statement LOOP until it finds one of GrandPaycodeID's that I need?
Maybe add the following line and if true to return to the top of the IF Then statement???
Else IF {PAYCAT1MM.GRANDPAYCODEID} = 11051
|