Search code examples
syntaxif-statementcrystal-reports

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"

Solution

  • 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";