Null Handling

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Prakash3366
Participant
Posts: 16
Joined: Wed Jan 30, 2008 3:22 am

Null Handling

Post by Prakash3366 »

Hi All

i have salary column , but few fields are null. If salary is null then i want 999 in the target otherwise i want the salary itself.

Ex:
Input:

ID|NAME|SALARY
101,RAY,10000
102,CHIRS,
103,RAM,20000
104,JESSY,

Output i want as :

ID|NAME|SALARY
101,RAY,10000
102,CHIRS,999
103,RAM,20000
104,JESSY,999

Thanks in advance.
PRAKASH S G
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

search for isNull or NullToZero
ddevdutt
Participant
Posts: 47
Joined: Wed Aug 22, 2007 2:38 pm

Post by ddevdutt »

NullToValue should get you your output
DD

Success is right around the corner
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You'd have to create a NullToValue transform as it does not ship with the Server product, but it is quite easy to write. Or do the equivalent IF-THEN-ELSE check directly in the derivation using IsNull() as noted.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Prakash3366
Participant
Posts: 16
Joined: Wed Jan 30, 2008 3:22 am

Null Handling

Post by Prakash3366 »

Thanks for everybody. I know NullToValue in parallel but in server if i use IF THEN ELSE , I am not getting the desired value.. i am getting only null values in place of null values in the target. so please reply..

Thanks
PRAKASH S G
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Post your syntax.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Prakash3366
Participant
Posts: 16
Joined: Wed Jan 30, 2008 3:22 am

Post by Prakash3366 »

chulett,
Thanks for your reply. i am putting the following syntax

If column=isNull then 999 else '0'

Please correct if i am wrong

Thanks
Prakash
PRAKASH S G
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

IsNull() is a function and you said you wanted to retain the value if not null so:

If IsNull(column) then 999 else column
-craig

"You can never have too many knives" -- Logan Nine Fingers
Prakash3366
Participant
Posts: 16
Joined: Wed Jan 30, 2008 3:22 am

Post by Prakash3366 »

Chulett,
Thanks for your quick reply and i have mentioned as you are said , but still i am not getting solution for this.

If IsNull(a.SALARY) then 999 else a.SALARY.
Here is the a is the source link.

if i put this condition , i am not getting 999 in the place of null, i am getting only null in the null place.
So please reply for the same..

Thanks
Last edited by Prakash3366 on Tue Jul 28, 2009 10:50 am, edited 1 time in total.
PRAKASH S G
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Then your Salary field is not null. You may need to add a check for that field being "empty" as well. What data type is it?
-craig

"You can never have too many knives" -- Logan Nine Fingers
Prakash3366
Participant
Posts: 16
Joined: Wed Jan 30, 2008 3:22 am

Post by Prakash3366 »

chulett,

I want to explain the job.

my source has three columns. ID, Name and salary.
the datatype of these columns is integer, varchar and integer respectively.
i checked option, Nullable is Yes for salary column. But still i am not getting desired result.
can you help me about this.

Thanks
PRAKASH S G
ddevdutt
Participant
Posts: 47
Joined: Wed Aug 22, 2007 2:38 pm

Post by ddevdutt »

Like Craig mentioned, you probably have values that are not null in the Salary field. Hence apart from checking for nulls, also check to see if those fields are empty.
DD

Success is right around the corner
Prakash3366
Participant
Posts: 16
Joined: Wed Jan 30, 2008 3:22 am

Post by Prakash3366 »

Hi

in salary column, i have 10 rows . In that two ,three fields are empty values. But still i am not getting the correct result. So now you can help me about this

Thanks
PRAKASH S G
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What is your source for this column - flat file? Database table? Something else entirely? Assuming the first but looking for confirmation.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Prakash3366
Participant
Posts: 16
Joined: Wed Jan 30, 2008 3:22 am

Post by Prakash3366 »

My Source is flat file


Thanks
PRAKASH S G
Post Reply