community.borland.com

Article #25703: How to do an OR condition within an IF statement

Problem:
I have trigger in which I would like to use an OR condition so I can test  to see if one of two
conditions is satisfied.  Here is the code giving the error:

IF (new.age=1) or (new.age=2) THEN
...
END
 
Interbase reported this error:

Statement failed, SQLCODE = -104
Dynamic SQL Error
-SQL error code = -104
-Token unknown - line 4, char 15
-or



Solution:
Note: This information was tested under InterBase version 5.0 and 5.5.


You need to put the entire expression containing the OR condition in parenthesis.  
Please see the  example below:

connect "c:temptest.gdb";
set term !!;

create trigger agelist  for dogs before insert
as
  begin  
 IF ((new.age=1) or (new.age=2)) THEN
        new.BREED="Puppy";

  end!!

set term ;!!

Notice that the entire expression the IF statement was evaluating was in parenthesis. 
This tells InterBase to look at everything inside the parenthesis as a condition to evaluate
as true or false.   Had you omittted the extra parenthesis, the IF condition would have gotten confused
when it got to the 'OR' operator.  It expected to see 'THEN' after the closed parenthesis, indicating 
the end of the condition that the IF statement evaluates.  Your code only had parenthesis around 
the  first condition preceding the OR.  That is why you got the error message.

Last Modified: 23-OCT-00