Strip zeros

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
deva
Participant
Posts: 104
Joined: Fri Dec 29, 2006 1:54 pm

Strip zeros

Post by deva »

Hi,
I have one decimal column wihc is nullable deciaml(9,2). My source is flat file and this column is comming as null.

So I am reading this column as varchar and in the next transformer I am doing the StringToDecimal(string) and loading into table.

But in the table it is loading as 0 (zero). I want to load it as null because of I am getting source as null.

table data type is decimal(9,2).

Please help me on that.
rameshrr3
Premium Member
Premium Member
Posts: 609
Joined: Mon May 10, 2004 3:32 am
Location: BRENTWOOD, TN

Post by rameshrr3 »

will this work for you ?

Code: Select all

If IsNull(string) Then SetNull() Else StringToDecimal(string)
deva
Participant
Posts: 104
Joined: Fri Dec 29, 2006 1:54 pm

Post by deva »

rameshrr3 wrote:will this work for you ?

Code: Select all

If IsNull(string) Then SetNull() Else StringToDecimal(string)
This is not working Still I am getting 0 into table
rjdickson
Participant
Posts: 378
Joined: Mon Jun 16, 2003 5:28 am
Location: Chicago, USA
Contact:

Post by rjdickson »

How about:

Code: Select all

If IsNull(string) or Len(Trim(string))=0 Then SetNull() Else StringToDecimal(string)
Regards,
Robert
Kryt0n
Participant
Posts: 584
Joined: Wed Jun 22, 2005 7:28 pm

Post by Kryt0n »

Have you got the field in DataStage set as not nullable at any point in the flow?
ankursaxena.2003
Participant
Posts: 96
Joined: Mon May 14, 2012 1:30 pm

Post by ankursaxena.2003 »

Put a transformer and do Ramesh's logic as shown below:

If IsNull(string) Then SetNull() Else StringToDecimal(string)

After transformer put a Copy Stage and write into Target Table and also write in Sequential file.
And check in Sequential file if you get Null.
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

Is the string coming in as null, "NULL" or is it an empty string (which is NOT the same as null!)? I expect that rjdickson's logic will work for you as it is probably an empty string and not a true null.

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
vamsi.4a6
Participant
Posts: 334
Joined: Sun Jan 22, 2012 7:06 am
Contact:

Post by vamsi.4a6 »

jwiles wrote:Is the string coming in as null, "NULL" or is it an empty string (which is NOT the same as null!)? I expect that rjdickson's logic will work for you as it is probably an empty string and not a true null.

Regards,
Could you please clarify the below point.From your post i understood null, "NULL" and empty string are different in Datastage

1)NULL fileds can be filtered by using IsNULL function

2)empty string fileds can be filtered by using Len(Trim(string))=0

3)How to filter the null fields in Datastage?


Please correct me if i am wrong for the above three points.
dr.murthy
Participant
Posts: 224
Joined: Sun Dec 07, 2008 8:47 am
Location: delhi

Post by dr.murthy »

Yes , you are correct NULL fileds will be filtered with ISNULL function and blank strings are filtered with Len(trim(string)) = 0.
But your source is an flat file so you cannot see the null values in a flat file. to filter the null values in a flat file you should check Len(trim(string)) = 0.
D.N .MURTHY
vamsi.4a6
Participant
Posts: 334
Joined: Sun Jan 22, 2012 7:06 am
Contact:

Post by vamsi.4a6 »

Thanks for the Reply

1)May i know what is the difference between null and NULL?

@dr.murthy

You mentioned since source is a flat file so you cannot see the null values in a flat file.May i know when null values occur in the source?Is it source dependent?
Kryt0n
Participant
Posts: 584
Joined: Wed Jun 22, 2005 7:28 pm

Post by Kryt0n »

dr.murthy wrote:Yes , you are correct NULL fileds will be filtered with ISNULL function and blank strings are filtered with Len(trim(string)) = 0.
But your source is an flat file so you cannot see the null values in a flat file. to filter the null values in a flat file you should check Len(trim(string)) = 0.
Not totally true, if a null field is defined as "" then any empty string in a sequential file will be treated as null
1)May i know what is the difference between null and NULL?
What you missed is that he stated "NULL" as in the literal value "NULL" not the null value
sajal.jain
Participant
Posts: 11
Joined: Sat Mar 13, 2010 12:00 am

Post by sajal.jain »

maybe worth trying with

If IsNull(string) Then SetNull() Else StringToDecimal(trimLeadingTrailing(string))


sometimes it attaches a extra space at the start[/b]
Major GungHo
sajal.jain
Participant
Posts: 11
Joined: Sat Mar 13, 2010 12:00 am

Post by sajal.jain »

maybe worth trying with

If IsNull(string) Then SetNull() Else StringToDecimal(trimLeadingTrailing(string))


sometimes it attaches a extra space at the start
Major GungHo
rameshrr3
Premium Member
Premium Member
Posts: 609
Joined: Mon May 10, 2004 3:32 am
Location: BRENTWOOD, TN

Post by rameshrr3 »

you can also use

Code: Select all

If Trim(NullToEmpty(string)) ='' Then SetNull() Else 
StringToDecimal(Trim(String))
and I guess it works better . I did not account for the possibility of empty data/spaces in my original derivation.

Does your string have Leading Zeroes ? That needs to be handled seperately.
Post Reply