Author |
Message
|
lung |
Posted: Tue Oct 08, 2002 6:36 pm Post subject: Multiple statements within CASE |
|
|
 Master
Joined: 27 Aug 2002 Posts: 291 Location: Malaysia
|
I am wondering if it is possible to have multiple ESQL statements within a CASE statement... For example, how can I make the following code work?
Code: |
CASE TxnCode
WHEN '0' THEN
...
... (multiple statements)
WHEN '1' THEN
...
...
... (and so forth)
END; |
Thanks! _________________ lung |
|
Back to top |
|
 |
lillo |
Posted: Wed Oct 09, 2002 12:24 am Post subject: |
|
|
Master
Joined: 11 Sep 2001 Posts: 224
|
Have you tried the BEGIN and END statements?
Cheers, _________________ Lillo
IBM Certified Specialist - WebSphere MQ |
|
Back to top |
|
 |
lung |
Posted: Wed Oct 09, 2002 9:51 pm Post subject: |
|
|
 Master
Joined: 27 Aug 2002 Posts: 291 Location: Malaysia
|
Do they work? BEGIN and END? I couldn't try them out yet...
Anyway I'm having trouble with the following code...
Code: |
CASE CurrentMonth
WHEN ’01’ THEN ’January’
WHEN ’02’ THEN ’February’
WHEN ’03’ THEN ’March’
WHEN ’04’ THEN ’April’
WHEN ’05’ THEN ’May’
WHEN ’06’ THEN ’June’
ELSE ’Second half of year’
END; |
Keeps getting syntax error! And I actually copied that code from one of the IBM pdf files... Can anyone identify where is the error?
 _________________ lung |
|
Back to top |
|
 |
Nyusser |
Posted: Thu Oct 10, 2002 1:31 am Post subject: |
|
|
Apprentice
Joined: 02 Jul 2002 Posts: 48
|
The CASE statement you use returns a value - which you have to deal with. For example:
Code: |
DECLARE CurrentMonth CHAR;
DECLARE MonthStr CHAR;
SET CurrentMonth = '01';
SET MonthStr = CASE CurrentMonth
WHEN '01' THEN 'January'
WHEN '02' THEN 'February'
WHEN '03' THEN 'March'
WHEN '04' THEN 'April'
WHEN '05' THEN 'May'
WHEN '06' THEN 'June'
ELSE 'Second half of year';
END;
|
And variable CurrentMonth will have value 'January'.
- Nyusser |
|
Back to top |
|
 |
lung |
Posted: Thu Oct 10, 2002 5:11 pm Post subject: |
|
|
 Master
Joined: 27 Aug 2002 Posts: 291 Location: Malaysia
|
Nyusser,
What if I doesn't want to SET MonthStr and want to do something else? (read my 1st post )
If 'CASE' only works when there is a 'SET' before it, then 'BEGIN' and 'END' clauses won't work with 'CASE', would they?
Thanks! _________________ lung |
|
Back to top |
|
 |
Nyusser |
Posted: Thu Oct 10, 2002 10:10 pm Post subject: |
|
|
Apprentice
Joined: 02 Jul 2002 Posts: 48
|
According to ESQL Reference (CSD2) CASE always returns a value, which means a result-value (e.g. THEN 'January') or result-expression (e.g. THEN SUBSTRING(CurrentMonth FROM 2 FOR 1) ) after WHEN. This means that ESQL's CASE function is not like CASE functions in other programming languages...
I guess, that the only way to execute several statements after WHEN is to call user-defined functions, which return appropriate values. BEGIN and END clauses probably won't work.
- Nyusser |
|
Back to top |
|
 |
lung |
Posted: Fri Oct 11, 2002 4:47 pm Post subject: |
|
|
 Master
Joined: 27 Aug 2002 Posts: 291 Location: Malaysia
|
Seems like the CREATE FUNCTION statement will also always return a value (a result-value)...
There seems to be something called CREATE PROCEDURE which may work (since it doesn't return a result-value) and something called a COMPOUND statement... Anyone has any idea how the COMPOUND statement works? I can't find any sample codes in the docs.
But then again the CREATE PROCEDURE statement will only work with the CALL statement, which doesn't work with the CASE statement...
Is there really no method in ESQL to make multiple IF-ELSE statements simpler? _________________ lung |
|
Back to top |
|
 |
lillo |
Posted: Sat Oct 12, 2002 4:41 am Post subject: |
|
|
Master
Joined: 11 Sep 2001 Posts: 224
|
Quote: |
Is there really no method in ESQL to make multiple IF-ELSE statements simpler? |
ELSIF functionality is implemented in CSD3. I really necessary improvement to ESQL.
Cheers _________________ Lillo
IBM Certified Specialist - WebSphere MQ |
|
Back to top |
|
 |
|