Page 1 of 2

Need to Perform Logic in Transformer

Posted: Wed May 29, 2013 12:24 pm
by DS_MJ
Hello:

Need to Perform the following logic in Transformer:

If NOT SUBSTR(MNO,1,1) BETWEEN ''0'' AND ''9''
AND NOT SUBSTR(MNO,2,1) BETWEEN ''0'' AND ''9''
AND NOT SUBSTR(MNO,3,1) BETWEEN ''0'' AND ''9''
THEN SUBSTR(MNO,1,3)
WHEN NOT SUBSTR(MNO,1,1) BETWEEN ''0'' AND ''9''
AND NOT SUBSTR(MNO,2,1) BETWEEN ''0'' AND ''9''
THEN SUBSTR(MNO,1,2)
WHEN NOT SUBSTR(MNO,1,1) BETWEEN ''0'' AND ''9''
THEN SUBSTR(MNO,1,1)
ELSE '' ''
END

I thought of creating a stage Variable and then call this Stage variable int he transformer.

But how do I do the above using If then Else and Field function?

Thanks.
MJ

Posted: Wed May 29, 2013 1:12 pm
by priyadarshikunal
First of all, what have you tried and what is the problem you are facing?

Posted: Wed May 29, 2013 1:37 pm
by DS_MJ
I was thinking to put this in stage variable and use the Field/Index function... but how to go about doing it is the question.
Could use someguidence on how to convert the above logic in Datastage.

Thanks

Posted: Wed May 29, 2013 2:23 pm
by chulett
You haven't posted anything to show you could use the Field() function here. Is your source any kind of delimited string? If not then you'll need to stick to substring.

Posted: Wed May 29, 2013 2:34 pm
by DS_MJ
Oh Sorry.

This field MNO is a VARCHAR of length 15 and has no delimiters in it. It is a combination of Characters and Numbers.
So if the first 3 fields are Character then we need to extract it to create a Prefix.
Need to select Positions that are not Numeric. If all positions are numeric the Prefix will be spaces.
This field - MNO contains many different formats. Each position must be evaluated individually hence the above query.

My Source is a dataset. I will use the transform to process this and other conversion and put it into a dataset.

DATASET -------> TRANSFORM ----------> DATASET

Posted: Wed May 29, 2013 2:36 pm
by priyadarshikunal
if = if
between = ">=" and "<="
case when = nested if then else
substring = []

Posted: Wed May 29, 2013 2:44 pm
by DS_MJ
Appreciate your quick response.
However, can you please help write it.

Thanks.

Posted: Wed May 29, 2013 4:27 pm
by ray.wurlod

Code: Select all

If IsValidInteger(Left(InLink.MNO,3)) Then Left(InLink.MNO,3) Else If IsValidInteger(Left(InLink.MNO,2)) Then Left(InLink.MNO,2) Else If IsValidInteger(Left(InLink.MNO,1)) Then Left(InLink.MNO,1) Else ""
There is no solution involving the Field() function.

Posted: Wed May 29, 2013 6:38 pm
by DS_MJ
Thank you Ray.
I am using 8.7
However, I dont see the function under Type conversion as "IsValidInteger"
Currently I am getting IsValidInteger is not defined.

Thanks.

Posted: Wed May 29, 2013 6:42 pm
by ray.wurlod
Sorry, that's a local modification here. You can use IsValidDecimal() in the same way.

Posted: Wed May 29, 2013 11:08 pm
by priyadarshikunal
I think the solution will return valid number values, however the requirement is to check if it is not number.

Try this

Code: Select all

if len(convert('0123456789','', left (MNO, 3))) =0 then " " else convert('0123456789','', left (MNO, 3))
Also you can use convert('0123456789','', left (MNO, 3)) in a stage variable.

PS: This is not my idea as I did not go through the entire logic, my bad, some one already replied to your mail on ittoolbox group. It was not visible correctly as quote was showing as " hence I mentioned it here. I think this code will work just fine.

Posted: Thu May 30, 2013 12:28 am
by ray.wurlod
priyadarshikunal wrote:the requirement is to check if it is not number.
No it isn't. Read the original post again.

Posted: Thu May 30, 2013 8:15 am
by priyadarshikunal
This is what the OP wrote in a third post.
DS_MJ wrote:So if the first 3 fields are Character then we need to extract it to create a Prefix.
Need to select Positions that are not Numeric. If all positions are numeric the Prefix will be spaces.

Posted: Thu May 30, 2013 8:22 am
by priyadarshikunal
Along with that there are too many NOT's in the query to make sure its not number. Unless I missed something which you noticed. Please enlighten in that case.

Posted: Thu May 30, 2013 9:03 am
by chulett
Lagomorph bifurcation.

:wink: