Himanshu
Himanshu

Reputation: 32612

Nested if else in Crystal Reports

I want to nest if-else statements in Crystal Reports, but I don't know the necessary syntax. How can I arrange something like this:

if table1.id <> "1" then
   if table1.name <> "a" then
      var1 := "Hello"
   else
      var1 := "Hi"
else
   var1 := "Bye"

Upvotes: 15

Views: 66759

Answers (2)

You can also nest your nested if statements and end with a semicolon on the last condition.

Stringvar variable

if {@cond}=1 then
  variable:="cond1"
else
  if {@cond}=2 then
    variable:="cond2"
else
   variable:="otherwise";

variable

Upvotes: 0

Arvo
Arvo

Reputation: 10580

You can use parenthesises to avoid ambiguity within nested if..else structures:

if {table1.id} <> 1 then
   (if {table1.name} <> "a" then
      var1 := "Hello"
   else
      var1 := "Hi";)
else
   var1 := "Bye";

Upvotes: 26

Related Questions