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 

DB2 SPUFI CASE statement question

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


Joined: 18 Jun 2004
Posts: 6
Topics: 4

PostPosted: Fri Jun 18, 2004 9:28 am    Post subject: DB2 SPUFI CASE statement question Reply with quote

Smile
Can someone offer some help with the below SQL
executing with "SPUFI" ,- "CASE" statements.
I've lookked at the SQL programmers guide, and cannot see
why the SQL below does not work?

SELECT NAME
CASE SEX_IND
WHEN = 'M' THEN 'MALE'
WHEN = 'F' THEN 'FEMALE'
ELSE 'UNKNOWN'
END AS GENDER
FROM EMP_TABLE;
--
-- aslo

--
SELECT SSN
CASE YEAR(CURRENT DATE - ADD_DT)
WHEN < 1 THEN '1 WEEK'
WHEN BETWEEN 1 AND 10 THEN '2 WEEKS'
WHEN BETWEEN 11 AND 20 THEN '3 WEEKS'
WHEN > 20 THEN '4 WEEKS'
ELSE 'UNKNOWN'
END AS VACATION
FROM EMP_TABLE;
Thank you.
Back to top
View user's profile Send private message
sriramla
Beginner


Joined: 22 Feb 2003
Posts: 74
Topics: 1

PostPosted: Fri Jun 18, 2004 12:22 pm    Post subject: Reply with quote

What is the sql error you get?
Error may be because there is no comma after first field( NAME or SSN).
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Fri Jun 18, 2004 1:50 pm    Post subject: Reply with quote

Salimo,

Code:

SELECT NAME
      ,CASE SEX_IND
            WHEN  'M' THEN 'MALE'     
            WHEN  'F' THEN 'FEMALE'   
            ELSE 'UNKNOWN'           
            END AS GENDER             
  FROM EMP_TABLE
  ;


Code:

SELECT SSN
      ,CASE                                                           
       WHEN (CURRENT DATE - ADD_DT) < 1               THEN '1 WEEK'
       WHEN (CURRENT DATE - ADD_DT) BETWEEN 1 AND 10  THEN '2 WEEK'
       WHEN (CURRENT DATE - ADD_DT) BETWEEN 11 AND 20 THEN '3 WEEK'
       WHEN (CURRENT DATE - ADD_DT) > 20              THEN '4 WEEK'
       ELSE 'UNKNOWN'                                             
       END AS VACATION
  FROM EMP_TABLE
  ;



Also check this link for a detailed explanation of the case expressions

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQH11/2.20.11?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
salimo
Beginner


Joined: 18 Jun 2004
Posts: 6
Topics: 4

PostPosted: Fri Jun 18, 2004 2:43 pm    Post subject: CASE in SPUFI SQL, -THANK YOU. Reply with quote

THANK YOU.
I was missing a comma after the column name on Select line.
AND
If your using a Date register the WHEN should refer to an interger, -
no ticks.
Thanks again for the reply.
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