Crystal Reports - If Then Else


Advertisements


The if-then-Else statement is the most basic of all the control flow statements. It tells your program to execute a certain section of code only if a particular condition meets true.

If you see the following If-Then-Else statement with Boolean operators, it has allowed you to pass multiple conditions in the formula and returning the value, if the condition is true.

If({PROJECT.Customer\Customer Name} [1 to 2] = "An" and

ToText({PROJECT.Time\Year}) [1] = "2") or

({Project.Customer\CUSTOMER NAME} [1 to 2] = "Ja" and

ToText({PROJECT.Time\Year}) [1] = "2") Then

"Five star rating CUSTOMER"

Else

"1 star rating CUSTOMER"

This statement says that when any of the condition is true (before and after OR operator), then it will print Five star rating customer otherwise it will print 1 star rating customer.

This formula has been saved and then added to the body of the report under the structure tab as shown in the following images −

Structure Tab

Structure Tab 1

A new column in the report has been added with the rating of the customers as mentioned in the TEST formula.



Advertisements