Concatenation in transformer ?

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
bond88
Participant
Posts: 109
Joined: Mon Oct 15, 2012 10:05 am
Location: USA

Concatenation in transformer ?

Post by bond88 »

Hi,
I want to concatenate '01' to a decimal value in a transformer stage. I tried it using stage variables but I didn't get exact result. Can you suggest me a way to achieve this?

Source data is like 201001, 201103, 200905 (6 digits, Integer/Decimal format)

Target should be like 20100101, 20110301, 20090501 (8 digits, Integer/Decimal format).

Thanks,
Bhanu
vinothkumar
Participant
Posts: 342
Joined: Tue Nov 04, 2008 10:38 am
Location: Chennai, India

Post by vinothkumar »

How did you try
bond88
Participant
Posts: 109
Joined: Mon Oct 15, 2012 10:05 am
Location: USA

Post by bond88 »

Stage Variable:

Dslink2.key:'01'-------DATE


Output link:

DATE_OUTPUT ----DATE

I am getting output as 201105.01 and that too if and only if I declare DATE_OUTPUT as varchar. If I convert it to decimal using stringtodecimal function then I am getting result as input (6 digits)
Bhanu
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You either need to convert to string, concat and then convert back or multiply the decimal by 100 then add 1.
-craig

"You can never have too many knives" -- Logan Nine Fingers
bond88
Participant
Posts: 109
Joined: Mon Oct 15, 2012 10:05 am
Location: USA

Post by bond88 »

Second method worked for me. I tried to convert to string and then to Decimal but didn't worked.

Thanks,
Bhanu
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

If you want to pursue the first method, show us the syntax you used and we'll go from there.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Concatenate is a string operator.

If applied to a Date data type then an implicit conversion to String is performed.

There is no implicit conversion for going the other way (string to date) so you have to specify an explicit data type conversion function such as StringToDate().
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
bond88
Participant
Posts: 109
Joined: Mon Oct 15, 2012 10:05 am
Location: USA

Post by bond88 »

Thanks Ray,
But I am not converting it in to Date type. I just want to concatenate 01 to a column type decimal. I wasn't able to get the required output. Later I multiplied decimal type value by 100 and added +1 to that to get required output as Chulett suggested.

Thank you for your input.
Bhanu
bond88
Participant
Posts: 109
Joined: Mon Oct 15, 2012 10:05 am
Location: USA

Post by bond88 »

chulett wrote:If you want to pursue the first method, show us the syntax you used and we'll go from there. ...

Stage:
DSLink2.KEY:'01' --- DATE (varchar)
StringToDecimal(DATE) --- Output (decimal)

Output:

Output --- Date_output (decimal)

But I am getting output same as input.

So, I modified logic like this

Stage:
DSLink2.KEY:CONC --- DATE (varchar)
StringToDecimal(DATE) --- Output (decimal)
01 ---- CONC (varchar)

Output:

Output --- Date_output (decimal)


Even I am getting output same as input I didn't understand really why it is happening like that.
Bhanu
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

As noted, you need to use DecimalToString on the incoming decimal first then concatenate and lastly use StringToDecimal to convert the end result back to a decimal.
-craig

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