I am not able to use a recursive query (BOM query) inside a trigger in
DB2 V7.2
Something like this:
CREATE TRIGGER my_trigger
AFTER INSERT ON my_table
REFERENCING NEW AS NRS
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
IF (WITH RPL (LVL, CODART, CODLOT, CQGEN) AS
(SELECT 1, ROOT.CODART, ROOT.CODLOT, ROOT.CQGEN
FROM my_table ROOT WHERE ROOT.CQGEN = NRS.CQGEN
UNION ALL
SELECT PARENT.LVL+1, CHILD.CODART, CHILD.CODLOT, CHILD.CQGEN
FROM RPL PARENT, my_table CHILD
WHERE PARENT.CODLOT=CHILD.CQGEN AND PARENT.LEVEL < 20 )
SELECT COUNT(*) FROM RPL WHERE CODART LIKE '4NAC45%') 0
THEN SIGNAL SQLSTATE '70444';
END 2 1952
On Oct 8, 9:22 am, Massimiliano Campagnoli <m...@paoloastori.com>
wrote:
I am not able to use a recursive query (BOM query) inside a trigger in
DB2 V7.2
Something like this:
CREATE TRIGGER my_trigger
AFTER INSERT ON my_table
REFERENCING NEW AS NRS
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
IF (WITH RPL (LVL, CODART, CODLOT, CQGEN) AS
(SELECT 1, ROOT.CODART, ROOT.CODLOT, ROOT.CQGEN
FROM my_table ROOT WHERE ROOT.CQGEN = NRS.CQGEN
UNION ALL
SELECT PARENT.LVL+1, CHILD.CODART, CHILD.CODLOT, CHILD.CQGEN
FROM RPL PARENT, my_table CHILD
WHERE PARENT.CODLOT=CHILD.CQGEN AND PARENT.LEVEL < 20 )
SELECT COUNT(*) FROM RPL WHERE CODART LIKE '4NAC45%') 0
THEN SIGNAL SQLSTATE '70444';
END
Please include the error you're receiving.
--Jeff
CREATE TRIGGER my_trigger
AFTER INSERT ON my_table
REFERENCING NEW AS NRS
FOR EACH ROW MODE DB2SQL
WITH RPL (LVL, CODART, CODLOT, CQGEN) AS
(SELECT 1, ROOT.CODART, ROOT.CODLOT, ROOT.CQGEN
FROM my_table ROOT WHERE ROOT.CQGEN = NRS.CQGEN
UNION ALL
SELECT PARENT.LVL+1, CHILD.CODART, CHILD.CODLOT, CHILD.CQGEN
FROM RPL PARENT, my_table CHILD
WHERE PARENT.CODLOT=CHILD.CQGEN AND PARENT.LEVEL < 20 )
SELECT CAST(RAISE_ERROR('70444', '') FROM RPL WHERE CODART
LIKE '4NAC45%'
WITH can't be nested (it's part of select-statement, not fullselect)
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: m3ckon |
last post by:
Hi there,
I'm a little stuck and would like some help
I need to create an update trigger which will run an update query on
another table.
However, What I need to do is update the other...
|
by: SS |
last post by:
Hi,
I don't want to refresh a web page to query and display database.
I want the page shows information immediately when database changes.
What kind of technology or method would be able to...
|
by: Alex Scollay |
last post by:
Let's say I have a column whose values are all 2-digit integers, e.g.
82 (though it's actually a varchar field).
From now on, the column will be able to have 2-digit as well as 3-digit
integers....
|
by: Philehof |
last post by:
Hi Group.
I would like to add some information to a query.
I tried to create a table with the information from the query but then
if i run the query again the additional data will be lost.
...
|
by: abhi81 |
last post by:
Hello All,
I have a table on which I have created a insert,Update and a Delete trigger. All these triggers write a entry to another audit table with the unique key for each table and the timestamp....
| |
by: cnplnsk |
last post by:
i am giving whole program of trigger plz point out any error if there
this program is in file and called as trig2.sql
drop trigger trig2;
delimiter $$
create trigger trig2 after insert on tab...
|
by: =?ISO-8859-1?Q?Gear=F3id?= |
last post by:
Hey,
This may sound odd, but is there anyway to catch the current or just
run query from inside a trigger? Kinda like how profiler displays the
query just as you've run it, along with all the...
|
by: Neil |
last post by:
I'm running an update query in SQL 7 from QA, and it runs forever. Has been
running for 20 minutes so far! The query is quite simple: update a single
field in a table, based on a join with another...
|
by: Rudolf Bargholz |
last post by:
Hi,
We have created triggers to log modifications to tables in our application.
The triggers work fine, just on one of the tables in our database the
triggers fail with the error message...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |