trigger -731 workaround??
Posted in 1995
Topics: Stored Procedures & SPL, Server Administration, Triggers, Constraints & Referential Integrity
The problem is: my user wants the number of days between the
disposition_date and the received_date excluding Saturdays, Sundays
and holidays. I've coded the following so far (I've yet to work on
excluding the Saturdays and Sundays part.) The update trigger works
fine. When I tried to also create the insert trigger, I encountered
the -731. Engine: Online 7.10.UD1. GUI: Powerbuilder which requires
the column to be on the database (or so I've been told) to make the
datawindow work correctly.
I have the following database called jimone:
Column name Type Nulls
----------- ---- -----
key serial no
text char(20) yes
received_date datetime year to fraction(5) yes
disposition_date datetime year to fraction(5) yes
days_between interval day(3) to day yes
and the following update trigger:
CREATE TRIGGER jimone_uUPDATE OF received_date, disposition_date ON jimone
REFERENCING NEW AS new_data
FOR EACH ROW(EXECUTE PROCEDURE work_day(new_data.received_date,
new_data.disposition_date) INTO days_between);
which executes the following procedure:
CREATE PROCEDURE work_day(from_date DATETIME YEAR TO FRACTION(5),to_date DATETIME YEAR TO FRACTION(5)) RETURNING INTERVAL DAY(3) TO
DAY;
DEFINE num_holiday INTEGER;
DEFINE num_days INTERVAL DAY(3) TO DAY;
LET num_days = to_date - from_date;
LET num_holiday = (SELECT count(*) FROM holiday_dates
WHERE holiday > from_date AND holiday < to_date);
LET num_days = num_days - num_holiday UNITS DAY;
IF num_days < INTERVAL (1) DAY(3) TO DAY THEN
RAISE EXCEPTION -746, 0, "Trigger failed - Days_Between is < 1";
END IF
return num_days;
END PROCEDURE;
But when I try to do the same thing on an insert, it fails with a -731
- which means you can't use days_between in an "into" clause of an
INSERT trigger.
CREATE TRIGGER jimone_iINSERT ON jimone
REFERENCING NEW AS new_data
FOR EACH ROW(EXECUTE PROCEDURE work_day(new_data.received_date,
new_data.disposition_date) INTO days_between);
Do you know of any workarounds to do this (to get the days_between
calculated from the stored procedure at insert time) preferably at the
engine level??
Tips/corrections/help is also solicited and welcome,
...Don Boothby, DBA, State of Indiana