473,385 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

IF statement as SELECT's argument for a DB2 Trigger

Hi,
I have a problem for a DB2 trigger that take records from a table and put them into another one.

I need to do a choice when i copy from a table to another. I made my trigger and it works but it's not perfect. So i need help to make it better.

Here is my trigger:

CREATE TRIGGER SAPR3.TR1_P_SGQ0400I AFTER INSERT ON SAPR3.SGQ0400I
REFERENCING NEW ROW AS NEW FOR EACH ROW MODE DB2SQL
WHEN (NEW.STATO = 'FOR_EXPORT')
BEGIN ATOMIC
INSERT INTO SAPR3.P_SGQ0400I(
KRICH,
BUKRS,
CANPR,
DTEVE,
DTFPI,
TIOPE,
CDAVV,
TIPLA,
STOPE,
KCONCE,
CARSE,
CODRIC,
DTDECR,
NOMRIC,
KFISCR,
KPIVAR,
FLTRD,
CODCLE,
DTDECC,
NOMCL,
KFISC,
KPIVA,
TIPME,
PRESA,
DTDECF,
CLMIS,
FORID,
FOCAP,
NCIV1,
NCIV2,
COMUN,
PROVI,
RID,
STATO,
ADB_SUBJECT,
ADB_SEQUENCE,
ADB_TIMESTAMP,
ADB_OPCODE,
/* ADB_SET_SEQUENCE,
ADB_UPDATE_ALL,
ADB_L_CMSEQUENCE, */
ADB_L_DELIVERY)
select
SELECT TRIM(NEW.KRICH), TRIM(NEW.BUKRS), TRIM(NEW.CANPR), sleexists , NEW.DTFPI, TRIM(NEW.TIOPE), TRIM(NEW.CDAVV), TRIM(NEW.TIPLA), TRIM(NEW.STOPE), TRIM(NEW.KCONCE), TRIM(NEW.CARSE), TRIM(NEW.CODRIC), NEW.DTDECR, TRIM(NEW.NOMRIC), TRIM(NEW.KFISCR), TRIM(NEW.KPIVAR), TRIM(NEW.FLTRD), TRIM(NEW.CODCLE), NEW.DTDECC, TRIM(NEW.NOMCL), TRIM(NEW.KFISC), TRIM(NEW.KPIVA), TRIM(NEW.TIPME), TRIM(NEW.PRESA), NEW.DTDECF, TRIM(NEW.CLMIS), TRIM(NEW.FORID), TRIM(NEW.FOCAP), TRIM(NEW.NCIV1), TRIM(NEW.NCIV2), TRIM(NEW.COMUN), TRIM(NEW.PROVI), TRIM(NEW.RID), TRIM(NEW.STATO), '', ADB_SEQ, CURRENT TIMESTAMP, 1, 'N'
FROM SAPR3.ADB_SEQTAB
WHERE PUB_TABLE = 'P_SGQ0400I';
UPDATE SAPR3.P_SGQ0400I SET DTEVE= NULL
WHERE DTEVE= 0;
/* O UPDATE SAPR3.P_SGQ0400I SET DTEVE= NULL
WHERE NEW.DTEVE= 0; */
UPDATE SAPR3.P_SGQ0400I SET DTFPI= NULL
WHERE DTFPI= 0;
UPDATE SAPR3.P_SGQ0400I SET DTDECR= NULL
WHERE DTDECR= 0;
UPDATE SAPR3.P_SGQ0400I SET DTEVE= NULL
WHERE DTDECC= 0;
UPDATE SAPR3.P_SGQ0400I SET DTDECF= NULL
WHERE DTDECF= 0;
UPDATE SAPR3.ADB_SEQTAB SET ADB_SEQ = ADB_SEQ + 1
WHERE PUB_TABLE = 'P_SGQ0400I';
END;

It's good until the table where i put the records is not big. But when the number of records increases it may have some TIME problem. Could anyone help me to make it better about the update?
thank you
Feb 16 '07 #1
0 3391

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Eddy Fontaine | last post by:
Hi there, Could somebody post some simple example how one can refer to a column in the 'deleted' temporary table within a trigger definition ? Should the 'deleted' and 'inserted' temp tables be...
1
by: Rebecca Lovelace | last post by:
I have a trigger on a table. I am trying to dynamically log the changed fields on the table to another table, so I am iterating through the bits in COLUMNS_UPDATED() to find what's changed, and...
0
by: Frank van Vugt | last post by:
L.S. Postgresql version 7.4.3 does not allow declaration of a 'for each statement' constraint trigger: db=# \h create constraint Command: CREATE CONSTRAINT TRIGGER Description: define a...
2
by: Dima Gofman | last post by:
I have a trigger on UPDATE on a table. I'm running some maintenance UPDATE and DELETE queries which I want the trigger to ignore but at the same time I want other UPDATE queries that other users...
1
by: filip1150 | last post by:
I'm trying to find if there is any performance diference between explicitly using a sequence in the insert statement to generate values for a column and doing this in an insert trigger. I...
3
by: orakelvin | last post by:
Hi I am geting an error ORA-04091 table is mutuating, trigger cannot seen it. The situation arise because I am having two table employee Id empcol 101 ...
0
by: imran haq | last post by:
Hi All, I have 3 rather Long Questions that are causing alot of trouble: I would appreciate all the help i can get and tried to use A post sent to atli in the past but it did not help... !) I...
10
by: JohnO | last post by:
Hi All, This question is related to iSeries V5R4 and db2. I want to implement an AFTER DELETE trigger to save the deleted rows to an archive table, I initially defined it as a FOR EACH...
10
by: gyanendar | last post by:
Hi All, I want to access new value after upadate in statement level trigger. But in my query I am getting old values. Here is the Trigger Code: CREATE OR REPLACE TRIGGER TEST_TRIGGER AFTER...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.