Page 1 of 1

position string

Posted: Wed Oct 11, 2006 11:37 am
by sainath
Hi
I have a string length of 288 characters.
I have some conditions like if position in string[122,125] = 'xyz'
then statement 1 else statement 2.

my question is can we sue incolumn.[122,125] tp return string
at this position.
thks

Posted: Wed Oct 11, 2006 11:49 am
by kcbland
You will always get back a string, unless the value is a NULL, you'll get a NULL. If the value is shorter in length than your position, you will get blank (you know quote-quote ""). Since you're using it in an If-Then-Else, you need to consider handling the NULL condition, which you're not.

You're also not insuring only 3 characters are returned because 122,125 means 125 characters returned. If the string is shorter than that, you won't get any padded characters. But, if there's extra values then you'll never get just "xyz".

Consider:

Code: Select all

If ISNULL(string) Then NullResult Else If string[125,1] # "" Then TooLongResult Else If string[122,3]="xyz" Then ThatResult Else DefaultResult

Posted: Wed Oct 11, 2006 12:35 pm
by roy
Hi,
sainath wrote:hi
Thanks for your quick reply .
This string cannot be null.

my quesition
position string[123 through 125] including decimals is numeric or ='n/a'
then return the string .
how can me do in datastage.
thks
What ken said is that you can use link.col[122,3] to extract the 122nd - 125th characters of any string (if they exist) then you can compare that string using the If ... Then ... Else syntax to apply your logic.
You may also use any DS basic function like Num() to determine if the string you got is numeric.

IHTH,

Posted: Wed Oct 11, 2006 3:08 pm
by ray.wurlod
<pedantry>
Character positions 122 through 125 total four characters. Therefore the second argument to substring needs to be 4.

And this will never be equal to "xyz" - a three character string can never be equal to a four character string.
</pedantry>