473,729 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple-condition trigger trouble

Hi experts,

I am having a hard time coding a trigger to handle multiple validation
conditions in DB2 UDB V8.1.9.. I thought that a single trigger might be
better than one-trigger-per-condition, but so far, no cigar. Here is
what I'd like to do (pseudo-code):

CREATE TRIGGER fp_insert
NO CASCADE BEFORE INSERT
ON DB2INST1.FILE_P ROPERTY
REFERENCING NEW AS n
FOR EACH ROW
BEGIN ATOMIC
WHEN (n.property_id = 175 and not exists (select 1 from
DICT_TOO_TRUTH where dict_value = n.property_valu e))
THEN RAISE_ERROR('70 001', 'Error')
WHEN (n.property_id = 187 and not exists (select 1 from
DICT_BIOPSY_TRU TH where dict_value = n.property_valu e))
THEN RAISE_ERROR('70 001', 'Error')
END;

DB2 does not like multiple "WHEN" conditions and I cannot find the
correct syntax for CASE. Can anyone help?

Thanks!

Alejandrina

Dec 1 '06 #1
7 8993
Create syntax you have there ... :-)

CREATE TRIGGER fp_insert
NO CASCADE BEFORE INSERT
ON DB2INST1.FILE_P ROPERTY
REFERENCING NEW AS n
FOR EACH ROW
WHEN (n.property_id = 175
and not exists (select 1 from DICT_TOO_TRUTH
where dict_value = n.property_valu e)
OR
n.property_id = 187
and not exists (select 1 from DICT_BIOPSY_TRU TH
where dict_value = n.property_valu e))
VALUES(RAISE_ER ROR('70001', 'Error'));

The trigger condition precedes the trigger body.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Dec 1 '06 #2
apattin wrote:
Hi experts,

I am having a hard time coding a trigger to handle multiple validation
conditions in DB2 UDB V8.1.9.. I thought that a single trigger might be
better than one-trigger-per-condition, but so far, no cigar. Here is
what I'd like to do (pseudo-code):

CREATE TRIGGER fp_insert
NO CASCADE BEFORE INSERT
ON DB2INST1.FILE_P ROPERTY
REFERENCING NEW AS n
FOR EACH ROW
BEGIN ATOMIC
WHEN (n.property_id = 175 and not exists (select 1 from
DICT_TOO_TRUTH where dict_value = n.property_valu e))
THEN RAISE_ERROR('70 001', 'Error')
WHEN (n.property_id = 187 and not exists (select 1 from
DICT_BIOPSY_TRU TH where dict_value = n.property_valu e))
THEN RAISE_ERROR('70 001', 'Error')
END;

DB2 does not like multiple "WHEN" conditions and I cannot find the
correct syntax for CASE. Can anyone help?
You could resort to IF ... THEN ... ELSE ... or a CASE statement. With the
latter, you need to put an CASE ... END CASE around the stuff in the atomic
compound.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Dec 1 '06 #3
Thanks Serge,

The solution you gave me works only if the trigger action is the same
for all cases, which I'd rather not have. My mistake, because I should
have said that I wanted to implement the following logic:

CREATE TRIGGER fp_insert
NO CASCADE BEFORE INSERT
ON DB2INST1.FILE_P ROPERTY
REFERENCING NEW AS n
FOR EACH ROW
BEGIN ATOMIC
WHEN (n.property_id = 175 and not exists (select 1 from
DICT_TOO_TRUTH where dict_value = n.property_valu e))
THEN RAISE_ERROR('70 001', 'Error in property 175')
WHEN (n.property_id = 187 and not exists (select 1 from
DICT_BIOPSY_TRU TH where dict_value = n.property_valu e))
THEN RAISE_ERROR('70 001', 'Error' in property 187)
END;

Notice the error messages are different. How can I do this?

Thanks again for the prompt response!

Alejandrina
Serge Rielau wrote:
Create syntax you have there ... :-)

CREATE TRIGGER fp_insert
NO CASCADE BEFORE INSERT
ON DB2INST1.FILE_P ROPERTY
REFERENCING NEW AS n
FOR EACH ROW
WHEN (n.property_id = 175
and not exists (select 1 from DICT_TOO_TRUTH
where dict_value = n.property_valu e)
OR
n.property_id = 187
and not exists (select 1 from DICT_BIOPSY_TRU TH
where dict_value = n.property_valu e))
VALUES(RAISE_ER ROR('70001', 'Error'));

The trigger condition precedes the trigger body.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Dec 2 '06 #4
I did not want to use IF because I thought CASE might be faster. Is
this true?

Can you give me an example of how you'd use CASE in my situation?

Alejandrina
Knut Stolze wrote:
apattin wrote:
Hi experts,

I am having a hard time coding a trigger to handle multiple validation
conditions in DB2 UDB V8.1.9.. I thought that a single trigger might be
better than one-trigger-per-condition, but so far, no cigar. Here is
what I'd like to do (pseudo-code):

CREATE TRIGGER fp_insert
NO CASCADE BEFORE INSERT
ON DB2INST1.FILE_P ROPERTY
REFERENCING NEW AS n
FOR EACH ROW
BEGIN ATOMIC
WHEN (n.property_id = 175 and not exists (select 1 from
DICT_TOO_TRUTH where dict_value = n.property_valu e))
THEN RAISE_ERROR('70 001', 'Error')
WHEN (n.property_id = 187 and not exists (select 1 from
DICT_BIOPSY_TRU TH where dict_value = n.property_valu e))
THEN RAISE_ERROR('70 001', 'Error')
END;

DB2 does not like multiple "WHEN" conditions and I cannot find the
correct syntax for CASE. Can anyone help?

You could resort to IF ... THEN ... ELSE ... or a CASE statement. With the
latter, you need to put an CASE ... END CASE around the stuff in the atomic
compound.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Dec 2 '06 #5
apattin wrote:
I did not want to use IF because I thought CASE might be faster. Is
this true?

Can you give me an example of how you'd use CASE in my situation?
case EXPRESSSION is faster than if STATEMENT. Yes

CREATE TRIGGER fp_insert
NO CASCADE BEFORE INSERT
ON DB2INST1.FILE_P ROPERTY
REFERENCING NEW AS n
FOR EACH ROW
SELECT CASE WHEN n.property_id = 175
and not exists (select 1 from DICT_TOO_TRUTH
where dict_value = n.property_valu e)
THEN CAST(raise_erro r('71001', 'hello') AS INT
WHEN
n.property_id = 187
and not exists (select 1 from DICT_BIOPSY_TRU TH
where dict_value = n.property_valu e))
RAISE_ERROR('70 001', 'World'));
END
FROM SYSIBM.SYSDUMMY 1;

raise_error() doesn't have a defined return type, hence the CAST.

Another option would be to use 2 triggers.
Should be the same cost :-)
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Dec 2 '06 #6
apattin wrote:
I did not want to use IF because I thought CASE might be faster. Is
this true?

Can you give me an example of how you'd use CASE in my situation?
case EXPRESSSION is faster than if STATEMENT. Yes

CREATE TRIGGER fp_insert
NO CASCADE BEFORE INSERT
ON DB2INST1.FILE_P ROPERTY
REFERENCING NEW AS n
FOR EACH ROW
SELECT CASE WHEN n.property_id = 175
and not exists (select 1 from DICT_TOO_TRUTH
where dict_value = n.property_valu e)
THEN CAST(raise_erro r('71001', 'hello') AS INT
WHEN
n.property_id = 187
and not exists (select 1 from DICT_BIOPSY_TRU TH
where dict_value = n.property_valu e)
THEN RAISE_ERROR('70 001', 'World')
END
FROM SYSIBM.SYSDUMMY 1;

raise_error() doesn't have a defined return type, hence the CAST.

Another option would be to use 2 triggers.
Should be the same cost :-)

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Dec 2 '06 #7
Worked like a charm. Thanks for unscrambling the trigger syntax for me!

Serge Rielau wrote:
apattin wrote:
I did not want to use IF because I thought CASE might be faster. Is
this true?

Can you give me an example of how you'd use CASE in my situation?
case EXPRESSSION is faster than if STATEMENT. Yes

CREATE TRIGGER fp_insert
NO CASCADE BEFORE INSERT
ON DB2INST1.FILE_P ROPERTY
REFERENCING NEW AS n
FOR EACH ROW
SELECT CASE WHEN n.property_id = 175
and not exists (select 1 from DICT_TOO_TRUTH
where dict_value = n.property_valu e)
THEN CAST(raise_erro r('71001', 'hello') AS INT
WHEN
n.property_id = 187
and not exists (select 1 from DICT_BIOPSY_TRU TH
where dict_value = n.property_valu e))
RAISE_ERROR('70 001', 'World'));
END
FROM SYSIBM.SYSDUMMY 1;

raise_error() doesn't have a defined return type, hence the CAST.

Another option would be to use 2 triggers.
Should be the same cost :-)
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Dec 5 '06 #8

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

Similar topics

6
7719
by: Rolf Wester | last post by:
Hi, I have a form with a select element with multiple="true". When using the GET method (I suppose the same happens with the POST method) I can seen that the form sends channels=CH1&channels=CH2 when CH1 and CH2 have been choosen. $_GET gives me "CH2". Is there any way to get all the choosen channels elements? I would be very appreciative for any help. Thank you in anticipation. Regards
66
5015
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
11
4968
by: Ohaya | last post by:
Hi, I'm trying to understand a situation where ASP seems to be "blocking" of "queuing" requests. This is on a Win2K Advanced Server, with IIS5. I've seen some posts (e.g., http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=Tidy7IDbDHA.2108%40cpmsftngxa06.phx.gbl) that indicate that ASP will queue up requests when they come in with the same "session".
6
4297
by: Ben Hallert | last post by:
Hi guys, I'm trying to figure out what bone headed mistake I made on something I put together. I've got a form (named 'context') that has a variable number of select-multiple inputs on it. Based on the number of variables passed through a GET string, I want to multiply the total number of selected items for each together to see how many possible combinations the selected items are generating. The following snippet of code...
22
23379
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete examples?
9
23082
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated to a pool. If I assign only one application to a applicaton pool and have multiple worker processes assigned to that pool. Will my application be processed by many worker processes?
9
2770
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and wizards. But, I have found that trying to do something "outside the norm" adds a rather large level of complexity and/or data replication. Background I have been commissioned to create a web-based application for a client. It has a formsaunthentication...
2
3661
by: areef.islam | last post by:
Hi, I am kinda new to javascript and I am having this problem with selecting multiple options from a select tag. Hope someone can help me out here. here is my code /////////////////////////////////////////////////////////////////////////////////////// <form action="whatever.php" method="post"> <select name="zip_code" onchange="makeRequest('getCity.php?state='+this.form.zip_code.options.value)" multiple="multiple" size="20">
4
4701
by: Matt Kruse | last post by:
While developing an internal IE6-only webapp, a discussion started about the 'best' way to apply classes to data tables across multiple pages. The two arguments were: 1. Apply a single class to each table. That class (possibly in combination with other classes on child elements) controls every part of the table - layout, colors, fonts, etc. Example: class="data" PROS: Easier to standardize, less specificity confusion, everything is...
35
9360
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from 500000 to 3200000 of a file whose size is say 20MB... how do i request a download which starts directly at 500000th byte... thank u cheers
0
8766
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
9428
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...
1
9217
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9158
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
8160
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
6722
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
6026
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
4535
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...
0
4799
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.