Subject | Triggers with null values |
---|---|
Author | sdbeames |
Post date | 2005-03-20T01:36:24Z |
Using Firebird V1.5.2.4731 why are these two triggers not equal for
the case where new.ESTIMATE is NULL?
CREATE OR ALTER TRIGGER JOBS_TG_BU for JOBS
BEFORE UPDATE AS
BEGIN
if (new.ESTIMATE is null or new.ESTIMATE = 0) then
begin
update DEBUG_TBL set DEBUG_CNT = DEBUG_CNT + 10;
execute procedure REMOVE_FROM_BACKLOG(new.JOBNO);
end
END
^
The above executes the code block when new.ESTIMATE is null, whereas
the one below doesn't.
CREATE OR ALTER TRIGGER JOBS_TG_BU for JOBS
BEFORE UPDATE AS
BEGIN
if (not(new.ESTIMATE <> 0)) then
begin
update DEBUG_TBL set DEBUG_CNT = DEBUG_CNT + 10;
execute procedure REMOVE_FROM_BACKLOG(new.JOBNO);
end
END
^
It seems as if (NULL <> 0) returns TRUE. I thought NULL comparisons
always returned false, as per
http://www.firebirdsql.org/manual/qsg15-firebird-sql.html
<Quote>
if (a <> b) then
MyVariable = 'Not equal';
else
MyVariable = 'Equal';
Here, MyVariable will be 'Equal' if a is NULL and b isn't, or vice
versa.
</Quote>
Thanks,
Steve
the case where new.ESTIMATE is NULL?
CREATE OR ALTER TRIGGER JOBS_TG_BU for JOBS
BEFORE UPDATE AS
BEGIN
if (new.ESTIMATE is null or new.ESTIMATE = 0) then
begin
update DEBUG_TBL set DEBUG_CNT = DEBUG_CNT + 10;
execute procedure REMOVE_FROM_BACKLOG(new.JOBNO);
end
END
^
The above executes the code block when new.ESTIMATE is null, whereas
the one below doesn't.
CREATE OR ALTER TRIGGER JOBS_TG_BU for JOBS
BEFORE UPDATE AS
BEGIN
if (not(new.ESTIMATE <> 0)) then
begin
update DEBUG_TBL set DEBUG_CNT = DEBUG_CNT + 10;
execute procedure REMOVE_FROM_BACKLOG(new.JOBNO);
end
END
^
It seems as if (NULL <> 0) returns TRUE. I thought NULL comparisons
always returned false, as per
http://www.firebirdsql.org/manual/qsg15-firebird-sql.html
<Quote>
if (a <> b) then
MyVariable = 'Not equal';
else
MyVariable = 'Equal';
Here, MyVariable will be 'Equal' if a is NULL and b isn't, or vice
versa.
</Quote>
Thanks,
Steve