Question : Create Insert Trigger

I've used the first to create an Update trigger for auditing changes to users permissions in a SyBase ASA Anywhere database.

The problem is that we aren't capturing data on newly created users.

I'm trying to add either a completely separate trigger or a combined trigger to capture both inserts and updates.  The second statement to create an insert trigger is failing with:

Line 1, Column 1
Could not Execute statement.
ASA Error -131: Syntax error near 'OF' on line 1

Any idea what I'm doing wrong?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
CREATE TRIGGER "DBA"."My_Field" AFTER UPDATE OF "My_Field"
    ORDER 3 ON "DBA"."USER_Data"
	REFERENCING OLD AS OrigVal NEW AS NewVal 
	FOR EACH ROW
BEGIN
        Insert into Narc_USER_INFO_Change (user_id,Field_Changed,New_Value,Original_Value,Changed_By)
        Values(OrigVal.user_id, 'My_Field',  COALESCE(NewVal.My_Field,'0'),  COALESCE(OrigVal.My_Field,'0'), CURRENT USER); 
END;
-----------------------------------------
CREATE TRIGGER "DBA"."My_Field_INSERT" AFTER INSERT OF "My_Field"
    ORDER 4 ON "DBA"."USER_Data"
	REFERENCING NEW AS NewVal 
	FOR EACH ROW
BEGIN
        Insert into Narc_USER_INFO_Change (user_id,Field_Changed,New_Value,Original_Value,Changed_By)
        Values(OrigVal.user_id, 'My_Field',  COALESCE(NewVal.My_Field,'0'),  0, CURRENT USER); 
END;
Open in New Window Select All

Answer : Create Insert Trigger

Yeah, it doesn't help that ASA support both the Watcom and the T-SQL syntaxes for a bunch of this stuff either.

You could try removing the alias to NewVal and just refer to NEW in the SQL, e.g. NEW.My_Field

Of course, it sure would be nice to know why it works in the UPDATE trigger but chokes in the INSERT trigger.

Regards,
Bill
Random Solutions  
 
programming4us programming4us