# Re: DECODE / CASE Question

From: <fitzjarrell_at_cox.net>
Date: Fri, 30 May 2008 12:44:15 -0700 (PDT)

On May 30, 12:51 pm, "ame..._at_iwc.net" <ame..._at_iwc.net> wrote:
> Hi,
>
> Say we have a very long DECODE statement like this:
>
> DECODE(2,-99999,0,2) + DECODE(5,-99999,0,5) + DECODE(7,-99999,0,7) -
> DECODE(8,-99999,0,8)  * DECODE(9,-99999,0,9) stuff
>
> Pardon the use of real numbers, that was for testing.
>
> Now, I want to basically say if the value of this is 0, then 0 should
> be returned, otherwise the result of the math should be returned.
>

Forgive me for being dense, but if the result of all of that math is 0 why aren't you simply returning the result of all of that math? Setting the value to 0 if the result of the calculations is 0 is makes what sense? The 'problem' solves itself, doesn't it?

> Can I use a case statement for this somehow?  Or do I enclose it
> around another DECODE?  Can I use the generated column alias???
>
> Thanks!

David Fitzjarrell Received on Fri May 30 2008 - 14:44:15 CDT

Original text of this message