p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Oracle (http://p2p.wrox.com/forumdisplay.php?f=105)
-   -   Or in a Case after where (http://p2p.wrox.com/showthread.php?t=82156)

sonnfan January 7th, 2011 08:34 AM

Or in a Case after where
 
Hi all,

I'm trying to display values of the last 3 month before this.

So i tried it with a case like:

Code:

...
AND "MONTH" = CASE

WHEN to_char(add_months(trunc(sysdate,'MM'),-1),'MM') = '12' THEN '10' OR '11' OR '12'
WHEN to_char(add_months(trunc(sysdate,'MM'),-1),'MM') = '01' THEN '11'  OR '12' OR '01'
...
END

The Problem is, it just won't work with the "or"s within the case. If I just take "...THEN '10' " it works perfectly, but i need it to be the three values. How can i solve that problem?

arbab February 28th, 2011 04:13 AM

It might help
 
*-*-* AND/OR *-*-*

The AND operator displays a record if both the first condition and the second condition is true.
p q p AND q
T T T
T F F
F T F
F F F
The OR operator displays a record if either the first condition or the second condition is true.
p q p OR q
T T T
T F T
F T T
F F F
SELECT CUST
FROM tblcust
WHERE cust > 6110148910985
OR (cust < 8 AND cust > 6)
*-*-*-*
try using brackets:

WHEN to_char(add_months(trunc(sysdate,'MM'),-1),'MM') = ('12' THEN '10') OR ('11' OR '12')


All times are GMT -4. The time now is 01:41 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.