If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Create Triggers By Join Of Two Tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-13-09, 14:25
Prabha Ramaswamy Prabha Ramaswamy is offline
Registered User
 
Join Date: Sep 2009
Posts: 2
Create Triggers By Join Of Two Tables

We have created an update trigger for a join of two tables which is given below,
CREATE TRIGGER X
AFTER INSERT ON A
REFERENCING NEW AS N
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
DECLARE TESTVAR1 CHAR(1);
DECLARE TESTVAR2 CHAR(9);
SET (TESTVAR1,TESTVAR2) = (SELECT TEST_VAR1 TESTVAR1,
SELECT TEST_VAR2 TESTVAR2
FROM B
WHERE B.XXX = N.XXX
AND B.YYY = 'C')
INSERT INTO C
VALUES (N.XXX,N.YYY,
:TESTVAR1,:TESTVAR2,N.ZZZ) ;
END

When executing the above trigger,it is failing with sql code -919.Can anybody please help me out in solving the error?
Reply With Quote
  #2 (permalink)  
Old 09-13-09, 14:54
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Before creating trigger, you made some basic syntax errors in SELECT and INSERT statement.

For example:
1)
SELECT TEST_VAR1 TESTVAR1, SELECT TEST_VAR2 TESTVAR2 FROM B ...

2)
SET (...) = (...) INSERT ...

3)
VALUES (N.XXX,N.YYY,:TESTVAR1,:TESTVAR2,...


And, what are your platform, DB2 version/release, full error message?
Reply With Quote
  #3 (permalink)  
Old 09-14-09, 01:14
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
Also, why the roundabout way to say
"insert into table
select n.xxx, n.yyy, b.TESTVAR1, b.TEST_VAR2
from table2
where..."

Dave
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On