String Comparison

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
appcon
Participant
Posts: 23
Joined: Wed Jul 07, 2004 8:11 am

String Comparison

Post by appcon »

I am working on a string comparision issue where I need to bring out a numbers start with a particular char or number.

Here is an example.

I have 123
234
235
237
456


I need to bring out any number that start with 2. So the result should be 234,235,237.

Has anyone come across this scenario. Any suggestions would be appreciated.

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

Post by chulett »

One way would be to simply substring the first character off and check to see if it is a '2'.

Code: Select all

If YourField[1,1] = "2" Then DoSomething Else DoSomethingElse
You could also do something similar in a Constraint:

Code: Select all

YourField[1,1] = "2"
Depends on what you mean by 'bring out'. You may need to add a 'trim' to that if there can be leading spaces involved.
-craig

"You can never have too many knives" -- Logan Nine Fingers
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

You can do your own experimentation on functions by writing a dummy routine and using the Test button to test various values. You will find this improves your knowledge of BASIC commands.
Create a routine, put into this routine the line:
Ans = left(234, 1), or
Ans = 234[1, 1] or
Ans = left(Arg1, 1)
Compile it and use the Test button to view the results. If your input field is numeric then you will be testing left(234, 1), if it's string you'll be testing left("234", 1). They both seem to give the same result. Looks like basic is very forgiving when it comes to sending a numeric field into a string function.
gh_amitava
Participant
Posts: 75
Joined: Tue May 13, 2003 4:14 am
Location: California
Contact:

Post by gh_amitava »

Hi,

For perfect result, You should use 'Trim' function before using 'Left' function because the argument is a string.. So your syntax should be like Left(Trim(string_var),1)

Regards
Amitava Ghosh
Post Reply