Compare 2 strings in transformer
Moderators: chulett, rschirm, roy
Compare 2 strings in transformer
Hi All,
I have a requirement to compare 2 columns and if they are same then print the 1st one. If both are different, then print the 1st concatenated with the 2nd.
Eg: The 2 columns are:
Col1 Col2
Air Air
Water Air
In the 1st case Col1=Col2, so the output should be Air
In the 2nd case Col1<>Col2, so the output should be WaterAir
In transformer, I am used If Then Else condition to do this, but it is concatenating both the columns irrespective of the condition.
Could you pls help.
I have a requirement to compare 2 columns and if they are same then print the 1st one. If both are different, then print the 1st concatenated with the 2nd.
Eg: The 2 columns are:
Col1 Col2
Air Air
Water Air
In the 1st case Col1=Col2, so the output should be Air
In the 2nd case Col1<>Col2, so the output should be WaterAir
In transformer, I am used If Then Else condition to do this, but it is concatenating both the columns irrespective of the condition.
Could you pls help.
-
- Participant
- Posts: 96
- Joined: Fri Apr 17, 2009 5:58 am
- Location: Delhi
Re: Compare 2 strings in transformer
Hi,
You may try the following derivation:
If (DSLink2.ID1 eq DSLink2.ID2) Then DSLink2.ID1 Else DSLink2.ID1 : DSLink2.ID2.
This should work.
Shri
You may try the following derivation:
If (DSLink2.ID1 eq DSLink2.ID2) Then DSLink2.ID1 Else DSLink2.ID1 : DSLink2.ID2.
This should work.
Shri
shalini11 wrote:Hi All,
I have a requirement to compare 2 columns and if they are same then print the 1st one. If both are different, then print the 1st concatenated with the 2nd.
Eg: The 2 columns are:
Col1 Col2
Air Air
Water Air
In the 1st case Col1=Col2, so the output should be Air
In the 2nd case Col1<>Col2, so the output should be WaterAir
In transformer, I am used If Then Else condition to do this, but it is concatenating both the columns irrespective of the condition.
Could you pls help.
Spaces are just another character and will match just fine. Post your exact derivations so we can see where you are going wrong.
Question: is it considered a match if one is "Air.Conditioner" with one space between words and the other is "Air..Conditioner" with two spaces? Or if one has no trailing spaces and the other does? I ask because that will control how you trim the fields before the comparison.
Question: is it considered a match if one is "Air.Conditioner" with one space between words and the other is "Air..Conditioner" with two spaces? Or if one has no trailing spaces and the other does? I ask because that will control how you trim the fields before the comparison.
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
Re: Compare 2 strings in transformer
[quote="adi_2_chaos"]Hi,
You may try the following derivation:
If (DSLink2.ID1 eq DSLink2.ID2) Then DSLink2.ID1 Else DSLink2.ID1 : DSLink2.ID2.
Hi adi_2_chaos,
What is eq in If (DSLink2.ID1 eq DSLink2.ID2)
Shalini,
Use directly as derivation for the output column.
Trim() will remove the leading and trailing spaces in a string. If you want to remove all the spaces in a string, you will have to use StripWhiteSpace().
You may try the following derivation:
If (DSLink2.ID1 eq DSLink2.ID2) Then DSLink2.ID1 Else DSLink2.ID1 : DSLink2.ID2.
Hi adi_2_chaos,
What is eq in If (DSLink2.ID1 eq DSLink2.ID2)
Shalini,
Use
Code: Select all
If (trim(col1)= trim(col2)) Then (col1) Else (col1:col2)
Trim() will remove the leading and trailing spaces in a string. If you want to remove all the spaces in a string, you will have to use StripWhiteSpace().
Thanks,
Mohan.A.Jasti.
Mohan.A.Jasti.