Single charcter match along with LIKE

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Single charcter match along with LIKE

Post by pandeesh »

Hi,

i need to check for a condition like

Code: Select all

 col1 LIKE a_%
where _ represents a single character.
We can go with index() function if we dont have any single char match there.
How this can be handled in transformer?

Thanks
pandeeswaran
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

With an Index() function. It searches for substrings (specify the substring - you don't need a wildcard character).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Can you be more specific regarding what you mean by "where _ represents a single character"? I'm unclear what the requirement is or what the underscore represents here... it must be a character rather than a number? :?

Typically when you want to do "like xxx%", meaning the string starts with a certain pattern, you can do a simple substring equality match but I can't tell if that would be appropriate here.
-craig

"You can never have too many knives" -- Logan Nine Fingers
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

Here the pattern I want to scan is a_b%.
It should match the strings like aab%.
The _ can be replaced by Any single character .
pandeeswaran
kandyshandy
Participant
Posts: 597
Joined: Fri Apr 29, 2005 6:19 am
Location: Singapore

Post by kandyshandy »

Check if this is what you want..

InputString[1,1] = 'a' and InputString[3,2] = 'b%'

or

InputString[1,1] = 'a' and InputString[3,1] = 'b'
Kandy
_________________
Try and Try again…You will succeed atlast!!
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

The original post is somewhat vague it the example looks like SQL, in which the % sign is a wildcard representing zero or more of any character, and also in which the _ is a wildcard representing any one character (standard SQL).

If you want to match on the % sign literally then use Kandy's first example.

If your unspoken rule is to handle % as standard SQL wildcard then use Kandy's second example.
Last edited by qt_ky on Thu Apr 19, 2012 9:46 pm, edited 1 time in total.
Choose a job you love, and you will never have to work a day in your life. - Confucius
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

Yes kandy. Thats the way I was also thinking about .
But when we have the pattern like %a_b%, I don't know how to match all the possible patterns .
pandeeswaran
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Seems you'd need to fall back to the Matches function for that, which would mean a Server job or a Server Shared Container.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kandyshandy
Participant
Posts: 597
Joined: Fri Apr 29, 2005 6:19 am
Location: Singapore

Post by kandyshandy »

pandeesh wrote:Yes kandy. Thats the way I was also thinking about .
But when we have the pattern like %a_b%, I don't know how to match all the possible patterns .
That is also possible. No time to give you the code.

Find the location of first 'a' using Index, then add 3 to it and see whether the character in that location is 'b'. That's it.
Kandy
_________________
Try and Try again…You will succeed atlast!!
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

It will become some more complex that if the number of a are more in the string and only one pattern is matching .
So we nee to recursively apply for all the occurrence of a .
Thanks for your help all
pandeeswaran
kandyshandy
Participant
Posts: 597
Joined: Fri Apr 29, 2005 6:19 am
Location: Singapore

Post by kandyshandy »

pandeesh wrote:So we nee to recursively apply for all the occurrence of a
Is this the actual requirement? What i thought is you want to select some string which has one occurrence of %a_b%.

Anyways, i don't think you can achieve this with a cake walk.
Kandy
_________________
Try and Try again…You will succeed atlast!!
Post Reply