RE: Multiple "When" in Trigger
Posted in 1997
Topics: Stored Procedures & SPL, Triggers, Constraints & Referential Integrity, Jobs, Consulting & Announcements
I think the problem is syntax for creating a trigger. At least the=20
following is accepted;
create table tt (p serial, i integer );
create table tt_1 (p integer, i integer );=20
create trigger tt_insert
insert on tt referencing new as post
for each row
when (post.i < 0) (insert into tt_1 values (post.p, post.i)),
when (post.i >=3D 0) (insert into tt_1 values (post.p, post.i));Note the use of a "," (Not a ";") to separate the different when
clauses. Therefore you could try instead:
create trigger example1
insert on tab_1 referencing new as not_old
for each row when (a=3D1) (execute spl_1()),
when (a=3D2) (execute spl_2());
Regards
Klaus
At 02:46 PM 10/16/97 -0500, you wrote:
}I don't think you can use multiple WHEN in a sql statement. A good=20
}workaround for your problem would be to call a stored procedure and=20
}leave it up to the stored procedure to do the switch statements.
}
}What I mean is:
}
}create trigger example1
}insert on tab_1 referencing new as not_old
}for each row execute sp_guard (a)
}
}Then your sp_guard procedure will accpet the parameter and call the=20
}corresponding procedure depending on the value of a.
}
}Your sp_guard procedure will be something like this:
}
}create procedure sp_guard(a int)
}
}If a=3D1 call spl_1 ()
}Elif a=3D2 call spl_2
}
}etc
}
}end if;
}
}end procedure
}
}
}Hope that helps,
}Sathya
}----------
}From: informix-list-owner(a)rmy.emory.edu; joschneidr(a)aol.com
}To: informix-list(a)rmy.emory.edu
}Subject: Multiple "When" in Trigger
}Date: Thursday, October 16, 1997 1:15PM
}
}Hy out there,
}my question may sound strange but is there a possibility to have more
}then one WHEN-Condition in a trigger ?
}
}I tried out something like this :
}
}create trigger example1
}insert on tab_1 referencing new as not_old
}for each row when (a=3D1) (execute spl_1());
} when (a=3D2) (execute spl_2());
}
}I tried out multiple version with changing syntax but there is always a
syntax
} error
}after the first "when" condition.
}
}Any help would be appreciated.
}
}
}
}
//////////////// ---------------------------------------------------- =
=20
////////// // Klaus Erik Markussen
////// / /// Support Consultant / Support Konsulent
///// // //// Informix Software A/S
//// // ///// Gladsaxevej 342
/// // ////// 2860 S=F8borg / Copenhagen
// // /////// Tel: +45 - 39 66 11 10 / Mobile: +45 - 40 45 73 05
/ /////////// E-mail klausmar@informix.com
//////////////// ----------------------------------------------------