How to replace null to something.

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
vsanghvi
Participant
Posts: 22
Joined: Wed Mar 09, 2005 4:47 pm

How to replace null to something.

Post by vsanghvi »

Hi,

I have job where I am reading data from DB2. Now the column I am reading can have null as well. I need to replace that null to "NONE". I did try with CHANGE function but it only works with empty string and not NULL. Is there any inbuilt function or do I need to write custom. Any idea ?

Thanks
V
logic
Participant
Posts: 115
Joined: Thu Feb 24, 2005 10:48 am

Post by logic »

IF THEN ELSE.........
dls
Premium Member
Premium Member
Posts: 96
Joined: Tue Sep 09, 2003 5:15 pm

Post by dls »

You might consider the DB2 function COALESCE.
Ambuj743
Premium Member
Premium Member
Posts: 8
Joined: Mon Sep 12, 2005 2:44 pm

Post by Ambuj743 »

If IsNull(column_name) Then .. Else column_name
vsanghvi
Participant
Posts: 22
Joined: Wed Mar 09, 2005 4:47 pm

Post by vsanghvi »

I tried this and it did not like the syntex. For e.g. I wrote If DSLink1.Code = NULL Then DSLink1="NONE" Else DSLink1.Code = "NONE"

Let me now if this is not correct. Or how do i correct it ? Thanks a lot
logic wrote:IF THEN ELSE.........
Ambuj743
Premium Member
Premium Member
Posts: 8
Joined: Mon Sep 12, 2005 2:44 pm

Post by Ambuj743 »

In the transformer stage use this line e.g I want to put # in the filed which is varchar datatype. if your datatype is integer use 0. It will work.

if isnull(DSLink1.Code ) then '#' else DSLink1.Code
LogicDude
Participant
Posts: 22
Joined: Tue Aug 30, 2005 5:08 pm
Location: CA

Post by LogicDude »

You are wrong. How can a NUll be equal to a Null? A Null is never equal to Null. It's not an integer where you can perform mathematical calculation or comparision.

Use what Ambuj said, "IsNull(column_name) Then .. Else column_name"

or you can use, " if nulltozero(column_name) = 0 then ... Else Column_name2"

You can find the "IsNull" function under: Functions --> Null Handling

IHTH
Raj
RaviM
Participant
Posts: 12
Joined: Thu Aug 19, 2004 4:13 pm

Re: How to replace null to something.

Post by RaviM »

vsanghvi wrote:Hi,

I have job where I am reading data from DB2. Now the column I am reading can have null as well. I need to replace that null to "NONE". I did try with CHANGE function but it only works with empty string and not NULL. Is there any inbuilt function or do I need to write custom. Any idea ?

Thanks
V
Try this :

If (Len(Trim(Link.Columnname))=0 Or IsNull(Trim(Link.Columnname)) Or Trim(Link.Columnname) ="" ) Then "NONE" Else Trim(Link.Columnname)


it will work
vsanghvi
Participant
Posts: 22
Joined: Wed Mar 09, 2005 4:47 pm

Post by vsanghvi »

Thanks Ambuj743 and others. This works great.
Ambuj743 wrote:In the transformer stage use this line e.g I want to put # in the filed which is varchar datatype. if your datatype is integer use 0. It will work.

if isnull(DSLink1.Code ) then '#' else DSLink1.Code
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Len(@NULL) returns 0. This may simplify your expression.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply