Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 375
  • Last Modified:

Pick not null names

How can i do this.


Name1 Name2 Name3  Name4

ABC          CDE    BBB

                                          KKK

                            MBC        LLL


So pick UP First non null name staring from Name 1,2,3,4

Final name
ABC
KKK
MBC
0
sam2929
Asked:
sam2929
  • 2
1 Solution
 
slightwv (䄆 Netminder) Commented:
Check out coalesce:

select coalesce(name1,name2,name3,name4) from sometable;
0
 
HuaMinChenBusiness AnalystCommented:
Use
...
where nvl(Name1,'')<>'' or nvl(Name2,'')<>'' ...

Open in new window

0
 
slightwv (䄆 Netminder) Commented:
HuaMinChen,

Your post doesn't make sense.

First piece that is wrong is that NVL(name1,'') doesn't do anything. An empty string in Oracle is considered a null so what that says is that if name1 is null, return null.

Second:
Given the data provided, please explain how your post will produce the expected results posted of:
Final name
ABC
KKK
MBC
0
 
awking00Commented:
Coalesce was designed precisely for this kind of query. It simply says return the first non-null value reached (null if all values are null). You should close this question and award slightwv the points without delay.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now