ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Boolean, check for NULL and case statement

Post new topic  Reply to topic
 Boolean, check for NULL and case statement « View previous topic :: View next topic » 
Author Message
mqsiuser
PostPosted: Wed Oct 29, 2014 1:01 am    Post subject: Boolean, check for NULL and case statement Reply with quote

Yatiri

Joined: 15 Apr 2008
Posts: 637
Location: Germany

Isn't this wrong:

Code:
SET myVariable =
CASE myBooleanVariable
WHEN NULL THEN <something>
ELSE <something else>
END;


And this right:

Code:
IF myBooleanVariable IS NULL THEN
   SET myVariable = <something>
ELSE
   SET myVariable = <something else>
END IF;


because it is... "myBooleanVariable IS NULL" and not "myBooleanVariable = NULL" ?
_________________
Just use REFERENCEs
Back to top
View user's profile Send private message
kimbert
PostPosted: Wed Oct 29, 2014 2:24 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

I am wondering why you are asking the question. What does the Knowledge Center say about the syntax of an ESQL CASE statement? Does the toolkit flag an error when you try it?
_________________
Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too.
Back to top
View user's profile Send private message
mqsiuser
PostPosted: Wed Oct 29, 2014 4:36 am    Post subject: Reply with quote

Yatiri

Joined: 15 Apr 2008
Posts: 637
Location: Germany

kimbert wrote:
I am wondering why you are asking the question.

I can understand that. I would just use "IF, ELSEIF and ELSE"...
... but this is a codebase I inherited and CASE is used all over the place (including for booleans and to check for "NULL").

We'd have to fix quite a bit if my assumption holds..

kimbert wrote:
What does the Knowledge Center say about the syntax of an ESQL CASE statement?

I found nothing specific to this particular problem:

The question is: How is "CASE ... WHEN" implemented (internally)? ... like I'd guess it is... implemented with "=" for everything (and not "IS (NOT)" for "NULL").

kimbert wrote:
Does the toolkit flag an error when you try it?

No! It also deploys well. I stepped through with the debugger and myBooleanVariable was NULL, but (with the "CASE WHEN") it stepped into the ELSE branch (which it shouldn't).

I adjusted the code to use "IF ELSE" and it worked (as expected).

The questions for us remains, if we'd have to go through the entire code base and adjust these "CASE WHEN" statements (for booleans and NULL).
_________________
Just use REFERENCEs
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed Oct 29, 2014 6:53 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Have you tried replacing WHEN NULL with WHEN IS NULL ?
Does it make a difference?
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
mqsiuser
PostPosted: Wed Oct 29, 2014 7:26 am    Post subject: Reply with quote

Yatiri

Joined: 15 Apr 2008
Posts: 637
Location: Germany

fjb_saper wrote:
Have you tried replacing WHEN NULL with WHEN IS NULL ?
Does it make a difference?

Syntax Error (in the Toolkit)

So won't let me.
_________________
Just use REFERENCEs
Back to top
View user's profile Send private message
mgk
PostPosted: Wed Oct 29, 2014 8:32 am    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

Your original example is wrong when checking for NULL but you do not need to switch to an IF statement, as you can simply use a 'searched' CASE expression rather than a 'simple' CASE statement like this:

Code:

SET myVariable = CASE 
                 WHEN myBooleanVariable IS UNKNOWN THEN 'I am NULL'
                 ELSE 'I am NOT NULL' 
                 END;


kind regards,
_________________
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
View user's profile Send private message
mqsiuser
PostPosted: Wed Oct 29, 2014 8:43 am    Post subject: Reply with quote

Yatiri

Joined: 15 Apr 2008
Posts: 637
Location: Germany



Will try that !

Sounds very good !

EDIT: I tried it with "NULL" instead of "UNKNOWN" (because that's just what I need) and debugged it. The debugger won't step into the CASE-statement (the sub-cases), ...

... so I am switching back and use (good old) "IF THEN (ELSEIF) ELSE" (the debugger steps into the individual cases, which is what I prefer).
_________________
Just use REFERENCEs
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Boolean, check for NULL and case statement
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.