COALESCE
Teradata Teradata Discussion Forums Teradata.com Discussion Forum
Visit Teradata.com
Home       Guidelines    Member List
Welcome Guest ( Login | Register )
        


This online forum is for user-to-user discussions of Teradata products, and is not an official customer support channel for Teradata. If you require direct assistance, please contact Teradata support.


COALESCE Expand / Collapse
Author
Message
Posted 10/12/2009 7:53:39 PM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 11/11/2009 1:12:32 PM
Posts: 14, Visits: 39
I need to write a query, so that it returns the non-null value like the following,
COALESCE (db_1.appl_no, db_2.appl_no) as Appl_nbr

But, db_1.appl_no has both '?' and ' '

here the coalesce function takes '?' as Null, but returns the blank field ' ' assuming it to be Not Null.

so i change the query like the following,


COALESCE (CASE WHEN db_1.appl_no = ' '
THEN NULL
ELSE db_1.appl_no END , db_2.applno as appl.no) as Appl_nbr



Is there any other better way???
Pls help


-Thank you


-Thank you
Post #17083
Posted 10/13/2009 1:47:28 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: Yesterday @ 3:55:54 AM
Posts: 111, Visits: 263
CASE WHEN db_1.appl_no = ' '
THEN db_2.appl_no
ELSE db_1.appl_no END as Appl_nbr

Looks neater!
Post #17085
Posted 10/13/2009 1:09:01 PM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 11/11/2009 1:12:32 PM
Posts: 14, Visits: 39
Jimm,
thanks for the reply.

here the problem is i need to pick the not null value between ---> COALESCE (db_1.appl_no, db_2.appl_no)

but the db_1.appl_no itself has three possibilites ---> Null value (?), Blank value (' ') & also a Variable number in it('211234423').
the coalesce considers the blank field (' ') in db_1.appl_no as not null and picks it ,


instead of picking the number value in the db_2.appl_no


so is there any other way instead of using coalesce (case when ' ' then .. end, ........)


-Thank you
Post #17091
Posted 10/13/2009 1:30:42 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: Yesterday @ 3:55:54 AM
Posts: 111, Visits: 263
No

CASE db_1.appl_no
WHEN ' '
THEN db_2.appl_no
WHEN NULL
THEN db_2.appl_no
ELSE db_1.appl_no END as Appl_nbr

If you look at the explain of a COALESCE, it is simply a short form of CASE.

Post #17092
Posted 10/21/2009 11:17:23 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 2 days ago @ 9:26:30 PM
Posts: 6, Visits: 11
Hi ,

I think you can try below.

( COALESCE(NULLIF ( db_1.appl_no,'') ,db_2.appl_no)

regards,
rupesh


Rupesh Baheti
Datawarehouse Analyst
OCBC Bank
Singapore
Post #17131
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 ( 0 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.


All times are GMT -5:00, Time now is 9:55pm

Powered By InstantForum.NET v4.1.4 © 2009
Execution: 0.078. 7 queries. Compression Disabled.