Subject | How do I use a variable as a fieldname in a trigger |
---|---|
Author | cornievs |
Post date | 2010-09-17T21:04:32Z |
I need to write a trigger that updates a field in another table on updating/inserting, but i can only determine which field when the inserting/updating is done. I try the following, but gets an error on the : characters.
SET TERM ^ ;
CREATE OR ALTER trigger hotel_bookings_detail_au0 for hotel_bookings_detail
active after update position 0
AS
declare variable OldUnitFieldName var15;
declare variable NewUnitFieldName var15;
begin
OldUnit = 'U' || OLD.UNIT_CODE;
NewUnit = 'U' || New.UNIT_CODE;
IF (old.STOCK_ITEM = -1)
THEN UPDATE room_status SET :OldUnitFieldName = 0
where room_status.dt between new.dt_from and new.dt_to-1;
IF (NEW.STOCK_ITEM = -1)
THEN UPDATE room_status SET :NewUnitFieldName = New.item_status
where room_status.dt between new.dt_from and new.dt_to-1;
end
^
Any help or pointers would be highly appreciated.
Regards
Cornie
SET TERM ^ ;
CREATE OR ALTER trigger hotel_bookings_detail_au0 for hotel_bookings_detail
active after update position 0
AS
declare variable OldUnitFieldName var15;
declare variable NewUnitFieldName var15;
begin
OldUnit = 'U' || OLD.UNIT_CODE;
NewUnit = 'U' || New.UNIT_CODE;
IF (old.STOCK_ITEM = -1)
THEN UPDATE room_status SET :OldUnitFieldName = 0
where room_status.dt between new.dt_from and new.dt_to-1;
IF (NEW.STOCK_ITEM = -1)
THEN UPDATE room_status SET :NewUnitFieldName = New.item_status
where room_status.dt between new.dt_from and new.dt_to-1;
end
^
Any help or pointers would be highly appreciated.
Regards
Cornie