MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Convert to logical 1 or 0

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
danm
Intermediate


Joined: 29 Jun 2004
Posts: 170
Topics: 73

PostPosted: Fri Nov 10, 2006 4:16 pm    Post subject: Convert to logical 1 or 0 Reply with quote

Column X may have any of these values: 'A', 'B','C' or 'D'. I want to show a logical '1' when columnX = 'B' and '0' for all others. This will work:
Code:

SELECT
    CASE COLX
        WHEN 'B' then 1
        Else 0
    END


Is there other way to produce the same result?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12383
Topics: 75
Location: San Jose

PostPosted: Fri Nov 10, 2006 4:25 pm    Post subject: Reply with quote

danm,

Try this untested sql

Code:

SELECT TRANSLATE(COLX,'1','B0','1')
  FROM TABLE                         
  ;         


Check this link for detailed explanation of the TRANSLATE scalar function

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQH11/3.2.86?SHELF=&DT=20010718164132&CASE=


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
danm
Intermediate


Joined: 29 Jun 2004
Posts: 170
Topics: 73

PostPosted: Mon Nov 13, 2006 9:06 am    Post subject: Reply with quote

Kolusu,

The result from your query is:
Code:

COL1  COL2
----  ----
A     A
B     1
C     C
D     D


The following will work:
Code:

SELECT COL1,
TRANSLATE(COL1,'1000','BACD')
FROM TABLE;


But this is not really exactly I am lookin for. I don't want to list every possible characters (may be unlimited) in the translation string.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
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


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group