View previous topic :: View next topic |
Author |
Message |
koolspark Beginner
Joined: 27 May 2010 Posts: 29 Topics: 13
|
Posted: Tue Nov 02, 2010 12:43 pm Post subject: help with CASE |
|
|
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 |
|
|
NASCAR9 Intermediate
Joined: 08 Oct 2004 Posts: 274 Topics: 52 Location: California
|
Posted: Tue Nov 02, 2010 12:48 pm Post subject: |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12369 Topics: 75 Location: San Jose
|
Posted: Tue Nov 02, 2010 1:01 pm Post subject: |
|
|
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 |
|
|
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Wed Nov 03, 2010 8:11 am Post subject: |
|
|
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 |
|
|
|
|