Subject | Re: [firebird-support] TMP$STATEMENTS - field "sql" in firebird ? |
---|---|
Author | Andi Voss |
Post date | 2005-06-21T00:19:18Z |
Helen Borrie schrieb:
CREATE TRIGGER update_table
FOR ARTIKEL
AFTER UPDATE OR INSERT
AS
DECLARE VARIABLE FNAME varchar(255);
DECLARE VARIABLE INHALT varchar(255);
BEGIN
FOR
SELECT DISTINCT
R.RDB$FIELD_NAME AS FNAME
FROM RDB$RELATION_FIELDS R
WHERE R.RDB$RELATION_NAME = 'ARTIKEL'
ORDER BY R.RDB$FIELD_POSITION
INTO :FNAME
DO
SUSPEND;
BEGIN
SELECT :FNAME FROM ARTIKEL A
WHERE A.artikelnr = OLD.artikelnr
INTO :INHALT;
SUSPEND;
IF ( :INHALT <> NEW.FNAME ) THEN
INSERT INTO UPDATE_DEF (id,artikelnr) VALUES
(GEN_ID(andi_gen,1),:INHALT);
END
END
I cant get it to work. I want to use a variable for the field in the
select statement. Is this generally possible?
Andi
> At 03:57 PM 20/06/2005 +0200, you wrote:Is something like this possible:
> In an After Update trigger on the table(s) that change, you would do
> something along the following lines:
>
> create trigger au_atable for atable
> active after update
> as
> begin
> if (exists (
> select id from blah
> where id = new.atable_id)) then
> begin
> if ((new.anotherfield <> old.anotherfield or ({various tests for
> null})) then
> update blah
> set whatever = new.anotherfield
> where id = new.atable_id;
> ....
> end
> else
> begin
> insert into blah (......)
> ....
> end
> end
CREATE TRIGGER update_table
FOR ARTIKEL
AFTER UPDATE OR INSERT
AS
DECLARE VARIABLE FNAME varchar(255);
DECLARE VARIABLE INHALT varchar(255);
BEGIN
FOR
SELECT DISTINCT
R.RDB$FIELD_NAME AS FNAME
FROM RDB$RELATION_FIELDS R
WHERE R.RDB$RELATION_NAME = 'ARTIKEL'
ORDER BY R.RDB$FIELD_POSITION
INTO :FNAME
DO
SUSPEND;
BEGIN
SELECT :FNAME FROM ARTIKEL A
WHERE A.artikelnr = OLD.artikelnr
INTO :INHALT;
SUSPEND;
IF ( :INHALT <> NEW.FNAME ) THEN
INSERT INTO UPDATE_DEF (id,artikelnr) VALUES
(GEN_ID(andi_gen,1),:INHALT);
END
END
I cant get it to work. I want to use a variable for the field in the
select statement. Is this generally possible?
Andi