Trim on variable having space as value

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
johnthomas
Participant
Posts: 56
Joined: Mon Oct 16, 2006 7:32 am

Trim on variable having space as value

Post by johnthomas »

I was trying to use trim function on a variable which has spaces . It seems it does not return a null . Any suggestion on the function to be used for the issue , so that it should return a null if the values is spaces
JT
thebird
Participant
Posts: 254
Joined: Thu Jan 06, 2005 12:11 am
Location: India
Contact:

Post by thebird »

Remeber - an empty string is not a null.

So, trimming a string which has spaces will not return a null - but an empty string - ''

If you need it to return a null, then you would have to explicitly set it to Null based on a condition of the sort -

Code: Select all

If trim(input.col)="" then SetNull() else trim(input.col)
Make sure that your input field is a Varchar.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Dont give any space between the two double quotes or it will always look for a single space which trim is getting rid off and it will never SetNull.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
johnthomas
Participant
Posts: 56
Joined: Mon Oct 16, 2006 7:32 am

Post by johnthomas »

In Case there is no space between double quotes , is the value after the trim is going to be null
JT
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Yes. Read the statement. If (after trimming there is nothing) then SetNull else (trim the incoming value of spaces and output the value). Better yet, test it.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Post Reply