Subject RE: [ib-support] Check with Trigger
Author Leyne, Sean
Walter,

> ...At least it was a small trigger:
>
> IF (EXISTS(SELECT PERSONENID FROM ADRESSE
> WHERE PERSONENID = NEW.PERSONENID AND ADRESSENTYP =
> NEW.ADRESSENTYP
> AND (GUELTIGVON IS NULL AND GUELTIGBIS IS NULL)
> OR (GUELTIGVON IS NULL AND NEW.GUELTIGVON IS NULL)
> OR (GUELTIGBIS IS NULL AND NEW.GUELTIGBIS IS NULL))) THEN
> EXCEPTION ADRESSE_UNGUELTIG;
>
> If I have some expressions between parenthesis, combined with
> and, than the
> whole block is only true, if all expressions are true. Is it right?
> I have:
> GUELTIGVON is Null
> GUELTIGBIS = 20.12.2002
> NEW.GUELTIGVON = 21.12.2002
> NEW.GUELTIGBIS is Null
> Why goes the trigger to exception? If I remove the last
> expression (GUELTIGBIS
> IS NULL AND NEW.GUELTIGBIS IS NULL), then it don't go to
> exception. Is the
> problem with the Null-State? Or with the parenthesis?

parenthesis

I think you really want:

IF (
EXISTS( SELECT PERSONENID FROM ADRESSE
WHERE
-> (PERSONENID = NEW.PERSONENID) AND
-> (ADRESSENTYP = NEW.ADRESSENTYP) AND
-> ((GUELTIGVON IS NULL AND GUELTIGBIS IS
NULL) OR
(GUELTIGVON IS NULL AND
NEW.GUELTIGVON IS NULL) OR
-> (GUELTIGBIS IS NULL AND
NEW.GUELTIGBIS IS NULL))
)
) THEN
EXCEPTION ADRESSE_UNGUELTIG;

Sean