Re: Irritating problem

From: Stephane Faroult <sfaroult_at_roughsea.com>
Date: Mon, 07 Nov 2011 23:42:05 +0100
Message-ID: <4EB85EBD.5080303_at_roughsea.com>



Lee,

    Jack provided you with a correct query but your problem is that you have CASEs with only one WHEN - and when the condition isn't satisfied (within one CASE) you don't know what the whole CASE expression should be, therefore it's NULL. You are each time adding four values, three of which are unknown, result unknown, which you cannot say is > 0, and it ends up as 'N'.

I hope it clarifies somehow.

-- 
Stephane Faroult
RoughSea Ltd <http://www.roughsea.com>
Konagora <http://www.konagora.com>
RoughSea Channel on Youtube <http://www.youtube.com/user/roughsealtd>



On 11/07/2011 10:36 PM, Robertson Lee - lerobe wrote:

> Chaps,
>
> Been stuck on a little bit of sql.
>
> Need to add up some columns with text values in them e.g 'One', 'Two'
> etc etc and see if the total is> 0.
>
> Thought I had it working but its not
>
> I am doing
>
> select CASE WHEN (CASE WHEN READERSHIP_OFTEN_SATURDAY='One'
> THEN 0.25 END)+
> (CASE WHEN READERSHIP_OFTEN_SATURDAY='Two'
> THEN 0.5 END)+
> (CASE WHEN READERSHIP_OFTEN_SATURDAY='Three'
> THEN 0.75 END)+
> (CASE WHEN READERSHIP_OFTEN_SATURDAY='Four'
> THEN 1 END)> 0 THEN 'Y' ELSE 'N' END AS Reader
> FROM lee;
>
> Data is as follows
> Two values in table for READERSHIP_OFTEN_SATURDAY
> One
> Four
>
> Both values are coming back as N when I would expect an Y.
>
> Any help appreciated, its going to be staring me in the face but its
> late and Im tired.
>
> TIA
> Lee
>
> ***************************************************************************
> The information contained in this communication is confidential, is
> intended only for the use of the recipient named above, and may be legally
> privileged.
>
> If the reader of this message is not the intended recipient, you are
> hereby notified that any dissemination, distribution or copying of this
> communication is strictly prohibited.
>
> If you have received this communication in error, please resend this
> communication to the sender and delete the original message or any copy
> of it from your computer system.
>
> Thank You.
> ****************************************************************************
>
> --
> http://www.freelists.org/webpage/oracle-l
>
>
>
-- http://www.freelists.org/webpage/oracle-l
Received on Mon Nov 07 2011 - 16:42:05 CST

Original text of this message