|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Environment NULL values |
« View previous topic :: View next topic » |
Author |
Message
|
Ramphart |
Posted: Wed Dec 22, 2004 1:46 pm Post subject: Environment NULL values |
|
|
 Disciple
Joined: 21 Jul 2004 Posts: 150 Location: South Africa, JHB
|
- I'm using WMQI 2.1 CSD 07 on Windows 2000.
Code 1
Code: |
IF Environment.Vars.Value <> 'Z' THEN
SET a = 1;
END IF; |
Code 2
Code: |
IF Environment.Vars.Value IS NULL THEN
SET a = 1;
END IF; |
Info
- The Environment.Vars.Value does not exist when the code runs (i.e. it is NULL)
- When I use Code 1 above, the Set a = 1 statement never executes.
- When I use Code 2 above, the Set a = 1 executes.
- How come Code 1 does not work? I would have thought that since NULL <> 'Z' Code 1 should also work
Regards _________________ Applications Architect |
|
Back to top |
|
 |
mgk |
Posted: Wed Dec 22, 2004 3:57 pm Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hi,
As the Value field does not exist, the left oprand of the <> operator resolves to NULL, therefore at this time it is as if you had written:
IF NULL <> 'Z' THEN ...
However, the result of any comparison of NULL with something else is NULL. Therefore the result of the above is NULL, so it is as if you had written:
IF NULL THEN...
The result of this can only be NULL not TRUE so the THEN block will not execute.
It is exactly for situations like this that (E)SQL has the IS NULL construct, as you have found.
Hope this helps. _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
Ramphart |
Posted: Wed Dec 22, 2004 9:33 pm Post subject: |
|
|
 Disciple
Joined: 21 Jul 2004 Posts: 150 Location: South Africa, JHB
|
I makes sense now. So I guess to be on the safe side one should really code as follows:
Code: |
IF Environment.Vars.Value <> 'Z' OR Environment.Vars.Value IS NULL THEN
SET a = 1;
END IF; |
_________________ Applications Architect |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Dec 23, 2004 4:26 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Be aware, as well, that when working with Environment, you may have a field that is NULL in the database that ends up being 'NULL' in Environment instead of NULL.
But that should be covered in your code, because 'NULL' is not NULL and is <> 'Z'. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|