473,508 Members | 2,360 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BOM QUERY IN TRIGGER

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

Oct 8 '07 #1
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

Oct 8 '07 #2
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
Oct 9 '07 #3

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

Similar topics

1
2192
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...
3
2980
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...
2
1471
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....
1
9017
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. ...
1
6190
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....
1
1750
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...
5
11140
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...
13
4145
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...
1
15880
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...
0
7223
marktang
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,...
0
7377
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...
1
7036
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...
0
7489
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...
0
5624
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,...
1
5047
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...
0
3191
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1547
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 ...

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.