Page 1 of 1

Concatenation in transformer ?

Posted: Mon Jun 24, 2013 3:36 pm
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,

Posted: Mon Jun 24, 2013 3:39 pm
by vinothkumar
How did you try

Posted: Mon Jun 24, 2013 3:44 pm
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)

Posted: Mon Jun 24, 2013 4:08 pm
by chulett
You either need to convert to string, concat and then convert back or multiply the decimal by 100 then add 1.

Posted: Mon Jun 24, 2013 4:54 pm
by bond88
Second method worked for me. I tried to convert to string and then to Decimal but didn't worked.

Thanks,

Posted: Mon Jun 24, 2013 9:17 pm
by chulett
If you want to pursue the first method, show us the syntax you used and we'll go from there.

Posted: Mon Jun 24, 2013 11:01 pm
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().

Posted: Tue Jun 25, 2013 3:21 pm
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.

Posted: Tue Jun 25, 2013 3:27 pm
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.

Posted: Tue Jun 25, 2013 5:56 pm
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.