Home » SQL & PL/SQL » SQL & PL/SQL » Decode problem
Decode problem [message #197264] Tue, 10 October 2006 16:08 Go to next message
Messages: 8
Registered: July 2005
Location: USA
Junior Member
I have a scenario here where in I need to pick a value comparing with 3 diff values from 3 different fields.

Lets say the fields are A,B and C. The scenario is:

If 'A' is not null then I need that Value and I dont even have to worry even if B and C have values
If A is null then I will need B provided B has a Value and if B does then I dont have to worry even if C has a value or not.
IF A and B both are nulls then I will need the value from C and if C is also empty then I give it a default value as 'NA'

I am trying to do this with Decode, but I am having trouble doing it.

Any suggestions as to how to approach this...

Thanks in advance
Re: Decode problem [message #197265 is a reply to message #197264] Tue, 10 October 2006 17:00 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
sql>select a, b, c, nvl(a, nvl(b, nvl(c, 'NA'))) result
  2    from t;

- - - --
a     a
  b   b
    c c

Or coalesce(a, b, c, 'NA') - as John Spencer pointed out on OTN where you posted this exact same question.

[Updated on: Tue, 10 October 2006 18:26]

Report message to a moderator

Previous Topic: Case Statement
Next Topic: Abt Trigger
Goto Forum:

Current Time: Fri Oct 28 14:50:50 CDT 2016

Total time taken to generate the page: 0.20283 seconds