Subject Check with Trigger
Author Walter Neumann
Hi all,
I am a Newbie in Database. I would like to check with a trigger before insert,
if the new row has collisions wither other existing rows. I have to check 4
columns: All rows with the same ID and the same typ must be checked, if the
starting date and the ending date cross the new dates. The date-fields could
be null, what means there is no starting or ending date. I tried the
following, but it doesent work:

DECLARE VARIABLE SEL_STRING;
BEGIN
IF (NEW.GUELTIGVON IS NULL) AND (NEW.GUELTIGBIS IS NOT NULL) THEN
SEL_STRING = ' AND GUELTIGVON IS NULL OR GUELTIGVON <= NEW.GUELTIGBIS'
ELSE IF (NEW.GUELTIGVON IS NOT NULL) AND (NEW.GUELTIGBIS >= NEW.GUELTIGVON)
THEN
SEL_STRING = ' AND GUELTIGBIS IS NULL OR GUELTIGBIS >= NEW.GUELTIGVON'
ELSE IF (NEW.GUELTIGVON IS NOT NULL) AND (NEW.GUELTIGBIS IS NOT NULL) THEN
SEL_STRING = ' AND GUELTIGVON IS NULL OR GUELTIGBIS IS NULL OR
(GUELTIGVON >= NEW.GUELTIGVON AND GUELTIGVON <= NEW.GUELTIGBIS) OR
(GUELTIGBIS <= NEW.GUELTIGBIS AND GUELTIGBIS >= NEW.GUELTIGVON) OR
(GUELTIGVON < NEW.GUELTIGVON AND GUELTIGBIS > NEW.GUELTIGBIS)';
SELECT PERSONENID FROM ADRESSE WHERE PERSONENID = NEW.PERSONENID
AND ADRESSENTYP = NEW.ADRESSENTYP||SEL_STRING;
IF PERSONENID > 0 THEN
EXCEPTION ADRESS_UNGUELTIG;
END

Can anyone help me?

Thankyou!

With regards,

Walter Neumann