Solved

DB2 trigger

Posted on 2009-07-16
3
425 Views
Last Modified: 2012-05-07
Hi,

I am trying to create this trigger that is updating the time and data in a table when a flag is changed in another table. This is the trigger.

The erros is : This statemens is not allowed.

Any ideas how can i make it work?

Thanks.
CREATE TRIGGER name
 

	BEFORE UPDATE ON table
 

	REFERENCING OLD AS OLDVAL 
 

	NEW AS NEWVAL 
 

	FOR EACH ROW 
 

	MODE DB2SQL 
 

	
 

	when (OLDVAL.flag != NEWVAL.flag )
 

		UPDATE other_table
 

				SET (FEADAT,FEATIM) = (CURRENT DATE, SUBSTR(CAST(current time AS CHAR(8)),1,2) ||  SUBSTR(CAST(current time AS CHAR(8)),4,2) )
 

					WHERE other_table.id =NEWVAL.id ;

Open in new window

0
Comment
Question by:se_1581
3 Comments
 
LVL 45

Assisted Solution

by:Kdo
Kdo earned 200 total points
ID: 24872213
Hi se,

I believe that this kind of trigger needs to be an AFTER trigger.  


Kent
0
 
LVL 18

Accepted Solution

by:
daveslash earned 300 total points
ID: 24872318

I agree with Kent. It should be an AFTER trigger.

Also, I think you need a BEGIN and END.

e.g.
 create trigger TR_MyTableAfterUpdate

   after update of flag on MyTable

   referencing new row as NewRow

               old row as OldRow

   for each row

   set option dbgview = *source

 Begin

    update SomeOtherTable s

    .... < some stuff >

    ;

 End;

Open in new window

0
 

Author Comment

by:se_1581
ID: 24872894
Thanks guys.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Database restore 8 78
Access Database - Manually changing xid value 7 57
Managing SQL log files, SQL Server 2014 6 74
SQL Server encoding for storing Indian languages 9 37
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now