Nested if else in Crystal Reports
Asked Answered
S

2

15

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"
Semang answered 25/6, 2012 at 6:6 Comment(0)
G
26

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";
Gunter answered 25/6, 2012 at 6:36 Comment(0)
A
0

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
Aeroembolism answered 23/3, 2022 at 20:11 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.