473,785 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need help with the trigger

Hi everybody!
I have an INSERT stattement like this:

insert into ELIGIBLE_PAY
select from ELIGIBLE_PAY_B
where cust_id = 999999;

after insert i would like to delete row from source table by creating the
following TRIGGER:

CREATE TRIGGER DEL_FROM_ELIGIB LE_PAY_B
AFTER INSERT
ON ELIGIBLE_PAY
REFERENCING NEW_TABLE AS newtab
FOR EACH STATEMENT
MODE DB2SQL
DELETE FROM ELIGIBLE_PAY_B
WHERE CUST_ID = newtab.CUST_ID;

and i got an error message:
SQL0206N "NEWTAB.CUS T_ID " is not valid in the context where it is used.
Any idea how to fix this trigger?
Thank's in advance.

--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums....m-db2/200807/1

Jul 8 '08 #1
3 1654
lenygold via DBMonster.com wrote:
Hi everybody!
I have an INSERT stattement like this:

insert into ELIGIBLE_PAY
select from ELIGIBLE_PAY_B
where cust_id = 999999;

after insert i would like to delete row from source table by creating the
following TRIGGER:

CREATE TRIGGER DEL_FROM_ELIGIB LE_PAY_B
AFTER INSERT
ON ELIGIBLE_PAY
REFERENCING NEW_TABLE AS newtab
FOR EACH STATEMENT
MODE DB2SQL
DELETE FROM ELIGIBLE_PAY_B
WHERE CUST_ID = newtab.CUST_ID;

and i got an error message:
SQL0206N "NEWTAB.CUS T_ID " is not valid in the context where it is used.
Any idea how to fix this trigger?
Thank's in advance.

CREATE TRIGGER DEL_FROM_ELIGIB LE_PAY_B
AFTER INSERT
ON ELIGIBLE_PAY
REFERENCING NEW AS new
FOR EACH ROW
MODE DB2SQL
DELETE FROM ELIGIBLE_PAY_B
WHERE CUST_ID = newtab.CUST_ID;
That should help.

Cheers
Serge

PS: The MODE DB2SQL stuff shouldn't be needed anymore unless you are on
a really old version.

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jul 8 '08 #2
Thak you very much it is working.

lenygold wrote:
>Hi everybody!
I have an INSERT stattement like this:

insert into ELIGIBLE_PAY
select from ELIGIBLE_PAY_B
where cust_id = 999999;

after insert i would like to delete row from source table by creating the
following TRIGGER:

CREATE TRIGGER DEL_FROM_ELIGIB LE_PAY_B
AFTER INSERT
ON ELIGIBLE_PAY
REFERENCING NEW_TABLE AS newtab
FOR EACH STATEMENT
MODE DB2SQL
DELETE FROM ELIGIBLE_PAY_B
WHERE CUST_ID = newtab.CUST_ID;

and i got an error message:
SQL0206N "NEWTAB.CUS T_ID " is not valid in the context where it is used.
Any idea how to fix this trigger?
Thank's in advance.
--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums....m-db2/200807/1

Jul 8 '08 #3
An INSERT followed by a DELETE looks like an UPDATE, or a MERGE to
me. Why the extra code instead of a single statement?
Jul 9 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2265
by: ZRexRider | last post by:
Hi, I have trigger that enforces the creation of a sortorder that is always 1 digit higher than the current highest on Inserts. This trigger works great if I add one row at a time so I think the logic is sound. However, I have a Stored Procedure that copies a bunch of rows into this table and all of the SortOrder values come up as 0. This stored procedure is doing an "Insert Into" and will insert numerous rows (10-20) at once.
7
2048
by: Lucio Chiessi | last post by:
Hi for all on this... I'm using MS SQL Server 7.0 SP4 in some customers to store some data from an aplication developed by me. I created an trigger to run on update. When I run an update command on it's table and the where condition returns only one row, the trigger is executed ok, but if where condition returns more than one rows, the trigger don't run. I don't know what happens there...
2
2528
by: Ken | last post by:
I got an Access database that need to be converted to Oracle 9i. Somehow the Trigger we created to simulate the "AUTO NUMBER" on Access could not create the sequence number as soon as the value has been inserted. The sequence number can only be created after we go to the second line. Please see the trigger below. Is there anyway we could create a trigger that could create the sequence number as soon as we enter a value? It should be...
4
4017
by: Peter Lin | last post by:
Dear all; I need to monitor a xml file so that I can update my data in hashtable, but the problem is it will trigger more than one event for a lastwrite action(I trigger this action by add something in the xml file using notepad). Here is my codes about using FilesystemWatcher fileWatcher=new FileSystemWatcher(); fileWatcher.Path=System.Environment.CurrentDirectory; fileWatcher.NotifyFilter=NotifyFilters.LastWrite;
5
2705
by: Raphael Bauduin | last post by:
Hi, I'm looking at the logging of a database we'll put in production soon. I've seen some posts on this list about history tables, like mentioned in http://www-106.ibm.com/developerworks/web/library/wa-dbdsgn2.html . I think I'll go that way too, but I still have some questions on the approach, and would appreciate any advice on it. Here are some questions I have: - is it possible to write only one function used for all logging...
2
3046
by: TJ Talluto | last post by:
Instead of putting the same 12 columns on every table (these 12 columns contain info about who created the record and when, for example)... It may be more efficient to make a new table to hold that data. This new table would act as a universal extension table. Instead of having FKs back to any particular table, it would contain regular keys that point back to whatever table::record is its source. I was thinking of using two keys only:
0
1833
by: Michael L | last post by:
Hi Guys(I apologize for the lengty post - Im trying to explain it as best i can) I've been cracking my head on this one for the past 24+ hours and i have tried creating the function in ten different ways and none of the versions i've made works exactly as it should. I have an array called $PageArray which contains a sorted list of all pages in my application. Im trying to create a recursive function(It dosn't need to be recursive if...
1
1458
by: nDaKota | last post by:
I am current converting PowerBuilder to C#. Now I'm having problem on triggers. I understand what a triggers does. The problem is what happens if a trigger is being triggered? Example: I execute a trigger say "trigger A"so the current process executed in the queue is paused. Then i issue another trigger "trigger B". Scenario 1: Considering the two triggers are not related. Upon issuing trigger B should trigger A be paused? Or Is it...
1
1716
by: candide_sh | last post by:
hello, I googled around some time but I found no solution for this issue (SS2000). I have a table tblB which has to be filled whenever in another table tblA records are inserted, updated or deleted. So I created one trigger which works fine for inserts and updates and fills my tblB. tblB is filled with other fields which I get from a view vwC.
12
2444
by: m1st | last post by:
I wanna create delete trigger. Idea is when user deletes the record from table trigger moves this record to another table (this table is copy has the same fields, types) But all this I want to do dinamic. I start so: ALTER TRIGGER ON . FOR DELETE AS BEGIN DECLARE @fieldname VARCHAR(100) DECLARE @val VARCHAR(100) DECLARE @b VARCHAR(MAX)
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.