Author |
Message
|
smdavies99 |
Posted: Wed Aug 22, 2012 2:42 am Post subject: Multiple Choices for a CASE when |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
If have a siruation the there are some 50 different possible (and growing) values for a field.
normally, I'd put a case statement like the following
Code: |
case cItem
when 'Type1' then
...
when 'Type2' then
...
etc
end case;
|
In the 50 values there are some 15 common actions I need to take. In theory something like this would be ideal
Code: |
case cItem
when 'Type1' or 'Type33' or 'Type49' then
...
when 'Type2' or 'Type16' or 'Type19' or 'Type20' then
...
etc
end case;
|
This compiles (on 7.0.0.4) but fails to deploy.
Quote: |
BIP2427E: (.SITREP_Master_Compute.ProcessMsg, 122.15) : The left operand of 'OR' operator is not a boolean expression.
The left operand of this operator must be a boolean expression.
Correct the syntax of your ESQL expression in node '.SITREP_Master_Compute.ProcessMsg', around line and column '122.15', then redeploy the message flow.
|
Is what I want to do possible. The infocentre seems to say so
'WHEN--Expression--THEN--Statements'
but I'm not so sure.
If this isn't possible then I'll just have to bite the bullet and case each one individually. I'd really prefer to use a CASE rather than an IF then ... elseif etc as the CASE option is IMHO far more maintainable. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Aug 22, 2012 2:52 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Does
Code: |
case
when cItem= 'Type1' or cItem = 'Type33' or cItem = 'Type49' then
...
etc
end case;
|
work? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
McueMart |
Posted: Wed Aug 22, 2012 2:52 am Post subject: |
|
|
 Chevalier
Joined: 29 Nov 2011 Posts: 490 Location: UK...somewhere
|
Code: |
case
when (cItem = 'Type1') or (cItem = 'Type33') or (cItem = 'Type49') then
...
when (cItem ='Type2') or (cItem = 'Type16') or (cItem = 'Type19') or (cItem = 'Type20') then
...
etc
end case;
|
That should work! |
|
Back to top |
|
 |
McueMart |
Posted: Wed Aug 22, 2012 2:53 am Post subject: |
|
|
 Chevalier
Joined: 29 Nov 2011 Posts: 490 Location: UK...somewhere
|
|
Back to top |
|
 |
mqjeff |
Posted: Wed Aug 22, 2012 4:11 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
McueMart wrote: |
@Vitor - you too quick! |
I was getting coffee. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Aug 22, 2012 4:31 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
mqjeff wrote: |
McueMart wrote: |
@Vitor - you too quick! |
I was getting coffee. |
An activity you perform marginally less often than breathing.
I was eating breakfast - what's your point? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
smdavies99 |
Posted: Wed Aug 22, 2012 4:49 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Thanks for the replies. IMHO the result is only slightly more readable that if..the...else when you compare it to
Code: |
if PLUGGH in ( 'Gold', 'Silver', 'Blood', 'Sweat', 'Tears' ) then
...
end if;
|
now if 'CASE' supported the 'IN' clause then I'd be happy.
and these goes that squadron of Vulcans flying taking off from Farnborough...  _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Aug 22, 2012 5:14 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
smdavies99 wrote: |
now if 'CASE' supported the 'IN' clause then I'd be happy. |
Doesn't it? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Aug 22, 2012 5:23 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Vitor wrote: |
smdavies99 wrote: |
now if 'CASE' supported the 'IN' clause then I'd be happy. |
Doesn't it? |
Yes it does.
(WMBv7.0.0.4, code as indicated above, extensively tested with 1 scenario....) _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mgk |
Posted: Wed Aug 22, 2012 5:30 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Quote: |
now if 'CASE' supported the 'IN' clause then I'd be happy. |
It does if you use the 'Searched CASE' statement:
Code: |
DECLARE cItem CHARACTER 'Type49';
CASE
WHEN cItem IN ('Type1', 'Type33', 'Type49') THEN
SET OutputRoot.XMLNSC.Test.Result = 'case 1';
WHEN cItem IN ('Type2', 'Type16', 'Type19', 'Type20') THEN
SET OutputRoot.XMLNSC.Test.Result = 'case 2';
END CASE; |
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 |
|
 |
mqjeff |
Posted: Wed Aug 22, 2012 5:33 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Vitor wrote: |
mqjeff wrote: |
McueMart wrote: |
@Vitor - you too quick! |
I was getting coffee. |
An activity you perform marginally less often than breathing.
I was eating breakfast - what's your point? |
If I kept coffee in the house, I would not leave the house. |
|
Back to top |
|
 |
smdavies99 |
Posted: Wed Aug 22, 2012 6:27 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Typical, that must have been the one combination I failed to try.
Thanks. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
|