Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DB2 trigger

Posted on 2009-07-16
3
Medium Priority
?
444 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 46

Assisted Solution

by:Kent Olsen
Kent Olsen earned 800 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:
Dave Ford earned 1200 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

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

704 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