passing one column value to another if it is null

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
Sirisha.lingisetty
Participant
Posts: 5
Joined: Tue Apr 04, 2006 1:15 am
Location: Site

passing one column value to another if it is null

Post by Sirisha.lingisetty »

Hi everybody.


Please help me to get out of this problem.

I have 3 address fileds in my file. In that , what I need to do is , if the value of address1 is null then address2 value need to be moved to address1 and accordingly address3 value need to be moved to address2.

This should be done for all the 3 fields.

My problem is If I create the unix file with empty value in one field, Datastage is taking that also as value.

For this , while Iam using IsNull() on the field it's assuming that there is a value,and it is not doing anything with my logic.

Thanks in Advance..
sanjeev_sithara
Participant
Posts: 15
Joined: Wed May 26, 2004 6:30 am

Post by sanjeev_sithara »

Hi,

Try doing a Isnull(Trim(field)) and then apply your logic .

HTH
Sirisha.lingisetty
Participant
Posts: 5
Joined: Tue Apr 04, 2006 1:15 am
Location: Site

Post by Sirisha.lingisetty »

Hi sanjeev,

I tried with your logic, but it's throwing one compilation error.

It seems that all the logic seems to be fine for me.

I wrote this line of code over there.

If IsNull(Trim(DSLink14.address2)) Then DSLink14.address3 Else DSLink14.address2

any comments/Suggestions appreciated.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

What is the data type for the field you specified?
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
Sirisha.lingisetty
Participant
Posts: 5
Joined: Tue Apr 04, 2006 1:15 am
Location: Site

Post by Sirisha.lingisetty »

Hi,

The datatype for the field is varchar.

I wrote the below line of code.

If IsNull(Trim(DSLink14.address2," ")) Then DSLink14.address3 Else DSLink14.address2
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

"" is not the same as NULL. This may be the root cause of your confusion. "" is a known value, NULL represents unknown value. So, if the value is "", then it is not null, and your logic behaves as you have described.

If the data are coming from a file, rather than from a table, there will be a stage property in which you can specify how null is represented in the file. If you get this right, then when that representation is found, the stage will automatically translate whatever you have specified into NULL for downstream processing.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Sirisha.lingisetty
Participant
Posts: 5
Joined: Tue Apr 04, 2006 1:15 am
Location: Site

Post by Sirisha.lingisetty »

Hi Ray,

Anyway the null handling with trim function is throwing one compilation error.

Please correct if my idea goes wrong.

I think, it can be done setNull() function.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

SetNull() will only work if the target column is defined as Nullable. But SetNull() does not help in deciding whether the input column is null. SetNull() generates a representation of NULL (unknown value).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Sirisha.lingisetty
Participant
Posts: 5
Joined: Tue Apr 04, 2006 1:15 am
Location: Site

Post by Sirisha.lingisetty »

Hi,

Any of my tries are not working.

Please help me how to check whether it is null or not for a string field.

I tried out with IsNull(),SrcInput field="",trim and all.

Please reply me ASAP
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

What is the error you get?
And what is the value avaialble in the input file?
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

What do you see when you View Data on the Sequential File stage? Are there any NULLs being delivered?

Etiquette note: we are an all volunteer site, we reply as and when we can. Requesting ASAP causes offence. If you want urgent support, arrange a premium contract with your support provider.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
dnsjain
Charter Member
Charter Member
Posts: 34
Joined: Thu May 08, 2003 2:12 pm

Post by dnsjain »

Try this:

If IsNull(Trim(DSLink14.address2," ")) Or Trim(DSLink14.address2) = "" Then DSLink14.address3 Else DSLink14.address2
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

check for two things,
1) whether its null or not
2) trim it and apply the len() function and see if its = 0

That should take care of it.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Post Reply