Re: CASE statement in WHERE Clause - Weird one

From: Geoff Muldoon <geoff.muldoon_at_trap.gmail.com>
Date: Thu, 22 May 2014 15:00:05 +1000
Message-ID: <MPG.2de82f65224c9005c4_at_news.albasani.net>


In article <eebebd14-6371-42f8-91d5-bdf4dffea93e_at_googlegroups.com>, artmerar_at_gmail.com says...
>
> Hi,
>
> I have this statement in my PL/SQL code:
>
> SELECT ROUND(AVG(pct_total),2)
> INTO v_average
> FROM pfp_to_buyer_agg
> WHERE registration_period >= '01-OCT-2012'
> AND period = v_period;
>
> Pretty straight forward. However, if the value of v_period is 1, I actually want the statement to read:
>
> SELECT ROUND(AVG(pct_total),2)
> INTO v_average
> FROM pfp_to_buyer_agg
> WHERE registration_period >= '01-OCT-2012'
> AND period IN (0,1);
>
>
> For any other value, it can read:
>
> SELECT ROUND(AVG(pct_total),2)
> INTO v_average
> FROM pfp_to_buyer_agg
> WHERE registration_period >= '01-OCT-2012'
> AND period = v_period;
>
> How can I made the WHERE clause conditional enough to know it should use an IN or an = ? Can this be done?

Although I'm certain it is achievable, why wouldn't you put your SELECT staements within a CASE statement rather than the other way around?

GM Received on Thu May 22 2014 - 07:00:05 CEST

Original text of this message