Substring using modify stage

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

vcsasikala
Participant
Posts: 26
Joined: Wed Jun 20, 2007 1:13 am
Location: Chennai

Substring using modify stage

Post by vcsasikala »

Hi,
I'm having date column in YYYYMMDD format. This is Varchar(8). I need to convert it to MMDDYYYY in modify stage. I don't want to use transformer. what is the specification do I need to give?

Is there any other way to do this without using transformer?


Thanks,
Sasikala
Regards,

Sasikala V C
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

There is no way within DataStage to accomplish this task without a Transformer or Build stage. If the data are coming from a file you might use a Filter command, if coming from a database you might use an SQL expression. But these are not what I include in "within DataStage" techniques.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Nripendra Chand
Premium Member
Premium Member
Posts: 196
Joined: Tue Nov 23, 2004 11:50 pm
Location: Sydney (Australia)

Post by Nripendra Chand »

use the following derivation in Modify stage:
Op_Column:date = date_from_string [%yyyy%mm%dd] (In_Column)

the output column will have date in default format defined at job level. If you want output date to be in 'MMDDYYYY' then change the date format at job level.

Thanks,
Nripendra
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

But it was stated that the source column is of type Date. Therefore you can not use date_from_string().
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

But it was stated that the source column is of type Date. Therefore you can not use date_from_string().
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Nripendra Chand
Premium Member
Premium Member
Posts: 196
Joined: Tue Nov 23, 2004 11:50 pm
Location: Sydney (Australia)

Post by Nripendra Chand »

hi Ray,

Sasikala mentioned that date column which is varchar. so i thought the source col is of varchar type which contains date.

Thanks,
Nripendra
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

:oops:
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
vcsasikala
Participant
Posts: 26
Joined: Wed Jun 20, 2007 1:13 am
Location: Chennai

Post by vcsasikala »

Thanks for reply Nripendra and Ray.


I tried this but I didn't get the output.
I gave specification : date2:date = date_from_string [%yyyy%mm%dd] (date1)

date1 in my input column varchar 8.
date2 is output column as datatype DATE.

there is no output from modify stage. Also job is not aborting and no warnings.

seq file ---green---> modify ---black---> dataset
Regards,

Sasikala V C
vcsasikala
Participant
Posts: 26
Joined: Wed Jun 20, 2007 1:13 am
Location: Chennai

Post by vcsasikala »

Hi,
I'm getting output values. I have changed the default format to %mm%dd%yyyy.
But output is still in the format YYYY-MM-DD.
I don't know why?
Regards,

Sasikala V C
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

If the format is YYYY-MM-DD then your mask should be "%yyyy-%mm-%dd"
vcsasikala
Participant
Posts: 26
Joined: Wed Jun 20, 2007 1:13 am
Location: Chennai

Post by vcsasikala »

My output should be in MMDDYYYY format. But I'm getting YYYY-MM-DD.

I have changed my default to %mm%dd%yyyy.

Do I need to change any other thing.
Regards,

Sasikala V C
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Sorry, I just wasn't paying attention to the first post and format there. Ok, so in your modify stage you have now successfully converted the string to a date. Now you need a 2nd modify stage which will convert this formatless date into a char datatype with appropriate formatting.
vcsasikala
Participant
Posts: 26
Joined: Wed Jun 20, 2007 1:13 am
Location: Chennai

Post by vcsasikala »

ok. I'm new to modify satge. can you please tell me how to get my desired format.
Regards,

Sasikala V C
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Please read the docs, the function is the opposite of the one you just used to generate the date.

Code: Select all

date3:string = string_from_date [%mm%dd%yyyy] (date2)
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

All is well. The date format you get when you view a date in the View Data browser is governed by the default date format string currently in force. The date itself, once it's been converted, is a binary form.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply