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 

help with CASE

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


Joined: 27 May 2010
Posts: 29
Topics: 13

PostPosted: Tue Nov 02, 2010 12:43 pm    Post subject: help with CASE Reply with quote

I've the following conde in my WHERE clause of a SELECT statement.
Code:

SELECT * FROM TAB1
WHERE TYP_C IN (
     CASE WHEN STAT_C = 'R' THEN
                        'R'
          ELSE      'P' || ',' || 'E' ||','||'C'

TYP_C & STAT_C are the columns in TAB1.

the ELSE part doen't show any syntax errors, but I'm not getting the data selected even the STAT_C value is 'P' or 'E' or 'C'.
how can I check for multiple values in ELSE part.
Please advise.
Back to top
View user's profile Send private message
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Tue Nov 02, 2010 12:48 pm    Post subject: Reply with quote

The reason is the ELSE means just that anything ELSE.

You need a Where Block for only the values you need.
_________________
Thanks,
NASCAR9
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Nov 02, 2010 1:01 pm    Post subject: Reply with quote

koolspark,

Isn't it simple without the case statement?

Code:

SELECT *                       
  FROM KTAB1               
  WHERE TYP_C IN ('P','E','C') 
     OR STAT_C = 'R'     
  ;


Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Wed Nov 03, 2010 8:11 am    Post subject: Reply with quote

kolusu and NASCAR set you on the right course. The CASE is adding confusion. Code the predicates with simple ANDs and ORs and use parenthesis to make sure you're getting what you want.

If you're still having trouble, post the requirements.
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