Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Any simpler way to avoid case

Posted on 2013-02-04
4
Medium Priority
?
258 Views
Last Modified: 2013-02-07
select case when d.arn_no is not null then to_char(d.arn_no)
                                                                     when d.boe_no is not null then d.boe_no
                                                                     else d.do_no end
from docs d

Is there any other simpler way without using case.?
0
Comment
Question by:sakthikumar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 500 total points
ID: 38850950
Looks like you are looking to find the first not null in a list of values.

If so, try coalesce:

coalesce(d.arn_no ,d.boe_no, d.do_no)
0
 
LVL 74

Assisted Solution

by:sdstuber
sdstuber earned 1000 total points
ID: 38850955
case seems like the simplest way but if you don't want to use it, you could try nvl2 and nvl

select nvl2(d.arn_no,nvl(d.boe_no,d.do_no),to_char(d.arn_no)) from docs d
0
 
LVL 35

Assisted Solution

by:johnsone
johnsone earned 500 total points
ID: 38850957
I believe that this will do the same thing:

nvl2(d.arn_no, to_char(d.arn_no), nvl2(d.boe_no, d.boe_no, d.do_no))
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 1000 total points
ID: 38850965
if you want to use coalesce, then all of the parameters must be of the compatible types.
i.e.  all numbers or all strings

based on your original code, it seems like arn_no is a number and the others are strings.
if so then try this...

coalesce(to_char(d.arn_no) ,d.boe_no, d.do_no)
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question