473,473 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to create a trigger that detects updates to columns (includingNULLs)

Hi,

The following trigger does fire if the column has a NULL or if a NULL
is updated to the column. Any ides how to fix this?

AFTER UPDATE
ON <table name>
REFERENCING
NEW AS n
OLD AS o
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC

IF (o.RESOURCE_TYPE <n.RESOURCE_TYPE) THEN
<sql statement here>.
END IF;

IF (o.RESOURCE_STATUS <n.RESOURCE_STATUS) THEN
<sql statement here>.
END IF;
END#
Thanks !

Carlos
Dec 12 '07 #1
5 1312
fu****@gmail.com wrote:
Hi,

The following trigger does
NOT
fire if the column has a NULL or if a NULL
is updated to the column. Any ides how to fix this?
IF (o.RESOURCE_TYPE <n.RESOURCE_TYPE OR
(o.resource_type IS NULL AND o.resource_type IS NOT NULL) OR
(o.resource_type IS NOT NULL AND o.resource_type IS NULL)
) THEN
<sql statement here>.
END IF;
Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Dec 12 '07 #2
On Dec 12, 10:38 pm, Serge Rielau <srie...@ca.ibm.comwrote:
fur...@gmail.com wrote:
Hi,
The following trigger does
NOT
fire if the column has a NULL or if a NULL
is updated to the column. Any ides how to fix this?
IF (o.RESOURCE_TYPE <n.RESOURCE_TYPE OR

(o.resource_type IS NULL AND o.resource_type IS NOT NULL) OR
(o.resource_type IS NOT NULL AND o.resource_type IS NULL)
) THEN
<sql statement here>.
END IF;
Not sure what happened to my post, so I'll repost.

Serge, is there a difference in how an IF stmt such as the above, and
an WHEN clause is evaluated in a trigger? For unknown reasons I have
always preferred WHEN over IF.

FWIW, if we can find a value outside the domain of resource_type (I
assumed 'x') the following will do the trick with less typing ;-)

coalesce(o.resource_type, 'x') <coalesce(n.resource_type, 'x')

/Lennart

Dec 13 '07 #3
Lennart wrote:
Serge, is there a difference in how an IF stmt such as the above, and
an WHEN clause is evaluated in a trigger? For unknown reasons I have
always preferred WHEN over IF.
IF statement is A LOT heavier than WHEN.
>
FWIW, if we can find a value outside the domain of resource_type (I
assumed 'x') the following will do the trick with less typing ;-)

coalesce(o.resource_type, 'x') <coalesce(n.resource_type, 'x')
Yes, that will work.

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Dec 13 '07 #4
On Dec 13, 6:35 pm, Serge Rielau <srie...@ca.ibm.comwrote:
Lennart wrote:
Serge, is there a difference in how an IF stmt such as the above, and
an WHEN clause is evaluated in a trigger? For unknown reasons I have
always preferred WHEN over IF.

IF statement is A LOT heavier than WHEN.
Thanks, now there is a known reason why I always preferred WHEN over
IF ;-)

/Lennart

[...]
Dec 13 '07 #5
On Dec 12, 4:38 pm, Serge Rielau <srie...@ca.ibm.comwrote:
fur...@gmail.com wrote:
Hi,
The following trigger does
NOT
fire if the column has a NULL or if a NULL
is updated to the column. Any ides how to fix this?
IF (o.RESOURCE_TYPE <n.RESOURCE_TYPE OR

(o.resource_type IS NULL AND o.resource_type IS NOT NULL) OR
(o.resource_type IS NOT NULL AND o.resource_type IS NULL)
) THEN
<sql statement here>.
END IF;

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab


It worked OK. Thanks for your help!!!
Carlos
Dec 13 '07 #6

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

Similar topics

4
by: Rustam Bogubaev | last post by:
Hi, I have a table with the following columns: ID INTEGEDR, Name VARCHAR(32), Surname VARCHAR(32), GroupID INTEGER, SubGroupOneID INTEGER, SubGroupTwoID...
9
by: Lauren Quantrell | last post by:
Is there a way to create a text file (such as a Windows Notepad file) by using a trigger on a table? What I want to do is to send a row of information to a table where the table: tblFileData has...
1
by: efinney | last post by:
Hi, I'm a newbie to sql server and this may be a really dumb question for some you. I'm trying to find some examples of sql server triggers that will set columns (e.g. the created and modified...
1
by: Tolga Yaramis via SQLMonster.com | last post by:
Hi All I have a question about generating dynmamicly If Update() statement in a trigger.. in My db, there is a table that holds some column names of an another table. for example; Columns...
1
by: Graeme Hinchliffe | last post by:
Hiya, Not had much experience with tiggers under postgres but am liking them so far. My problem is this. I am writing an updates system, postgres holds the master copy of the database, any...
7
by: aj | last post by:
DB2 LUW 8.2 FP5 (or is it 8.1 FP11?) I am CALLing a stored procedure from a trigger in order to maintain a column-level audit trail. Not only do I need to store a record of the INSERT, but also...
27
by: max | last post by:
Hello, I am a newbye, and I'm trying to write a simple application. I have five tables with three columns; all tables are identical; I need to change some data in the first table and let VB...
2
by: lakuma | last post by:
Hi, I have a table called A (say) with columns called name, place, animal and thing. I would want to write an on insert trigger on this table, which would create a table with the name of the...
3
by: Yas | last post by:
Hi everyone I am trying to create a DELETE Trigger. I have 2 tables. Table1 and Table2. Table 2 has all the same fields and records as Table1 + 1 extra column "date_removed" I would like that...
0
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
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...
0
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,...
0
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...
0
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
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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.