Solved

Update trigger not firing if initial value is null

Posted on 2008-06-20
3
497 Views
Last Modified: 2010-04-21
Hi. I have an update trigger that does not fire initially, using MS SQL 2000.  

If old_value <> new_value then....

If the old_value is <Null>, it does not fire.
If I enter in a number, and enter in a different number,  it does fire.

What am I missing?    Thanks.
0
Comment
Question by:D4430
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
balochdude earned 250 total points
ID: 21832243
just put a check if old_value is null then old_value = 1 (or some more appropriate value).

for example, i am doing the following in one our triggers::
       IF @max_line_number IS NULL
      BEGIN
            SET @max_line_number = 1000
      END
      ELSE
      BEGIN
            SET @max_line_number = @max_line_number + 1
      END
0
 

Author Closing Comment

by:D4430
ID: 31469202
Thanks.
0
 
LVL 27

Expert Comment

by:MikeToole
ID: 21832399
From BOL:
A value of NULL indicates that the value is unknown. A value of NULL is different from an empty or zero value. No two null values are equal. Comparisons between two null values, or between a NULL and any other value, return unknown because the value of each NULL is unknown.

Therefore use:

If (old_value <> new_value) or old_value is null

or, for completeness:

If (old_value <> new_value) or old_value is null or new_value is null

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question