Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wild Cards question.

Status
Not open for further replies.

CapsuleCorpJX

IS-IT--Management
Jun 23, 2004
70
0
0
US
What is the escape character for wild-cards?

% means 0 to many characters.
_ means 1 character.

What if I want to search for "_" literally?
 
From the SQL reference - Volume 5

The following example illustrates the use of ESCAPE:

To look for the pattern ‘95%’ in a string such as ‘Result is 95% effective’, if Result is the field to be checked, use:

WHERE Result LIKE ‘%95Z%%’ ESCAPE ‘Z’

This clause finds the value ‘95%’.
 
Found the answer:

...
TRIM(TESTFIELD) like 'Testing_me'c || '_Y'
...

the c char means anything before this is a literal.

So here are examples that will match the condition above:
Testing_mexY
Testing_me4Y
Testing_me_Y

Those that will not match:
TestingXme_Y
Testing_meXXY
 
Hi CapsuleCorpJX,
interesting, i've never seen that "'....'c" before, i only knew it from Hexadecimal Literals.

But to disappoint you, it returns TestingXme_Y, too (at least when i run that query).

Why don't you simply use jgerstb's proposal, it's Standard SQL:
TRIM(TESTFIELD) like 'Testing\_me_Y' ESCAPE '\'

Dieter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top