Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Replacement to CASE statement in DB2.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
maheshhh

New User


Joined: 10 May 2005
Posts: 6
Location: Hyderabad

PostPosted: Wed Jul 19, 2006 3:27 pm    Post subject: Replacement to CASE statement in DB2.
Reply with quote

Hi,

I would like to know whether there is any alternate mechanism to CASE statement in DB2. My requirement is as below.

Col1 Col2
----- ------
0001 A
0002 P1
0003 P2
0004 T
0005 E
0006 R
0007 X

My requirement is to select the records sorting them based on Col2 as below.

T
E
X
A
R
P2
P1

Please help me in this regard.

Thanks,
Mahesh.
Back to top
View user's profile Send private message

Jerry

New User


Joined: 16 Sep 2005
Posts: 42

PostPosted: Wed Jul 19, 2006 5:36 pm    Post subject:
Reply with quote

Hi Mahesh,

You said:

sorting them based on Col2 as below

Can you please explain the sort please.
Back to top
View user's profile Send private message
maheshhh

New User


Joined: 10 May 2005
Posts: 6
Location: Hyderabad

PostPosted: Wed Jul 19, 2006 6:47 pm    Post subject: Re: Replacement to CASE statement in DB2.
Reply with quote

Hi Jerry,

Let me put it more clear. I want to have the below order after opening the cursor in the application.

Code:
Col1  Col2
----- ------
0004  T
0005  E
0007  X
0001  A
0006  R
0003  P2
0002  P1


This can be done using the below query.

Code:
SELECT Col1, Col2, CASE Col2
                        WHEN 'T'  THEN '0'
                        WHEN 'E'  THEN '1'
                        WHEN 'X'  THEN '2'
                        WHEN 'A'  THEN '3'
                        WHEN 'R'  THEN '4'
                        WHEN 'P2' THEN '5'
                        WHEN 'P1' THEN '6'
                   END CASE
  FROM Table ORDER BY 3;


Thanks,
Mahesh.
Back to top
View user's profile Send private message
Jerry

New User


Joined: 16 Sep 2005
Posts: 42

PostPosted: Wed Jul 19, 2006 8:41 pm    Post subject:
Reply with quote

Hi Mahesh,

How about using TRANSLATE?

You can try this:

SELECT Col1, TRANSLATE(REPLACE(REPLACE(COL2,'P1','6)),'P2','5'),'01234','TEXA') FROM Table ORDER BY 3;
Back to top
View user's profile Send private message
maheshhh

New User


Joined: 10 May 2005
Posts: 6
Location: Hyderabad

PostPosted: Thu Jul 20, 2006 3:53 pm    Post subject: Re: Replacement to CASE statement in DB2.
Reply with quote

Hi Jerry,

Thanks for the suggestion. I need to check the performance of the replace statement.

Thansks & Regards,
Mahesh.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts WER268A OUTREC STATEMENT : SYNTAX E... frozenblood87 SYNCSORT 12 Sat Aug 26, 2017 9:45 pm
No new posts Suppress value reported by BREAK in D... Learncoholic DFSORT/ICETOOL 3 Wed Aug 16, 2017 6:03 pm
No new posts ON 2 AND EVERY 1 - Statement ??? UmeySan COBOL Programming 2 Tue Jul 25, 2017 1:20 pm
No new posts RFE: DB2 support for mixed case names. Pedro DB2 0 Tue Jul 04, 2017 1:32 am
No new posts ROUNDED Problem with COMPUTE statement shalem COBOL Programming 11 Thu Feb 09, 2017 8:16 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us