select status_a,status_b from test
how to decode status_a
,status_b
below values using oracle decode function aand if one of the values of status_a or status_b is null.
if status_a='Y' and status_b='Y' then 'Y'
if status_a='Y' and status_b='N' then 'N'
if status_a='N' and status_b='Y' then 'N'
if status_a='N' and status_b='N' then 'N'
Regards,
Chaituhara
Why do you want to use DECODE
? CASE
would seem like a much better fit
CASE WHEN status_a = 'Y' and status_b = 'Y' THEN 'Y'
WHEN status_a = 'Y' and status_b = 'N' THEN 'N'
WHEN status_a = 'N' and status_b = 'Y' THEN 'N'
WHEN status_a = 'N' and status_b = 'N' THEN 'N'
END
Of course, the logic you posted does not appear to make sense. The only way that status_a = 'Y' or status_b = 'Y'
would evaluate to FALSE while status_a = 'Y' or status_b = 'N'
evaluated to TRUE would be if status_a = 'N'
and status_b = 'N'
. But that means that the third and fourth branch would never be reached. If you meant and
rather than or
, the logic would make sense. But in that case, you could simplify it to
CASE WHEN status_a = 'Y' and status_b = 'Y' THEN 'Y'
ELSE 'N'
END
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With