timestamp to integer

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
marpadga18
Premium Member
Premium Member
Posts: 96
Joined: Fri Aug 20, 2010 8:51 am

timestamp to integer

Post by marpadga18 »

hi
I am having a source column as timestamp and my target column is integer.

column
2011-07-29 00:00:00.000

in xfm
I am doing
in.column[1,4]:in.column[6,7]:in.column[9,10] but is is giving me 0 in the output
I did this beofre it worked long back but now it is not working.could you tell me what is the problem.Thanks all
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

The substring operators do not work from start position to end position as you've coded it but rather they use start position and length.
-craig

"You can never have too many knives" -- Logan Nine Fingers
marpadga18
Premium Member
Premium Member
Posts: 96
Joined: Fri Aug 20, 2010 8:51 am

Post by marpadga18 »

hi chutlet

Is there nay way to do chutlet....I am trying to remove "-" so that it becomes integer but could you tell me how to acheive it.
Thanks M
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I already did tell you how to achieve it - correct your syntax.
-craig

"You can never have too many knives" -- Logan Nine Fingers
marpadga18
Premium Member
Premium Member
Posts: 96
Joined: Fri Aug 20, 2010 8:51 am

Post by marpadga18 »

Hi chutlet I tried in transformer with this syntax

in.column[1,4]:in.column[6,7]:in.column[9,10] when I validated this syntax it is valid I could not find any syntax errors if you could correct me that would be great.

Thanks M
ankursaxena.2003
Participant
Posts: 96
Joined: Mon May 14, 2012 1:30 pm

Post by ankursaxena.2003 »

Initially you will have to convert the TimeStamp to String using TimestampToString(%timestamp%,[%"%yyyy-%mm-%dd %hh:%nn:%ss"%]) function.

After wards you can apply your substring function. But, as Chulett said your syntax is wrong. It should be as shown below:

in.column[1,4]:in.column[6,2]:in.column[9,2]

And later on if you need then you can convert this String to Decimal.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Once more with feeling - you have (as one example) "in.column[6,7]" where you are telling it to substring from position 6 to position 7. That is not the correct syntax. You need to tell it to start in position 6 and substring out 2 characters: "in.column[6,2]"

Once they are all correct, you should be much closer to your goal.
-craig

"You can never have too many knives" -- Logan Nine Fingers
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

The syntax is correct; the values are incorrect. :wink:
Choose a job you love, and you will never have to work a day in your life. - Confucius
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Therefore, the syntax is incorrect. :D
-craig

"You can never have too many knives" -- Logan Nine Fingers
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

Ahhhh, but... there were no syntax errors. :shock:
Choose a job you love, and you will never have to work a day in your life. - Confucius
vamsi.4a6
Participant
Posts: 334
Joined: Sun Jan 22, 2012 7:06 am
Contact:

Post by vamsi.4a6 »

@chullet
Here source is Timestamp so can i apply substring operator directly or do i need to convert Timestamp to string and then i need to apply substring operator

As per my knowledge we can not apply substring operator directly to timestamp we need to convert timestamp to string before applying substring operator.Please correct me if i am wrong?
marpadga18
Premium Member
Premium Member
Posts: 96
Joined: Fri Aug 20, 2010 8:51 am

Post by marpadga18 »

chulett wrote:Therefore, the syntax is incorrect. :D
Hi Chutlet thanks for correcting me. What you said is right.
Thanks for all
chandra.shekhar@tcs.com
Premium Member
Premium Member
Posts: 353
Joined: Mon Jan 17, 2011 5:03 am
Location: Mumbai, India

Post by chandra.shekhar@tcs.com »

No need to use substr and then concatenating your column.
This will work too 8)

Code: Select all

TimestampToString(%timestamp%,["%yyyy%mm%dd"])
Thanx and Regards,
ETL User
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

True. My primary goal here was to correct the mis-use of the substring operator. As noted, they're not needed at all to accomplish the goal here, however if one is going to use them they need to be used correctly. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply