How to avoid wildcard characters in query

Hello.

I am trying to avoid (or somehow convert to string) wildcard characters in my query for example (only end of query):

WHERE searchstring LIKE '% 123_ %'

is it possible to somehow sql treat 123_ as string and not to treat character _ as wildcard.

I am using:
sSql = sSql + " AND user LIKE '%" & Text1.Text & "%'"

now when in Text1.Text is found square bracket character [ it produces error, how can I solve this problem?

Thanks.
damirselAsked:
Who is Participating?
 
MarcRavenCommented:
if you want to use a wildcard to look for, as i want to look for  a _, then you have to place the wildcard in square brackets: so like "*123[_]*"

Good luck, Marc
0
 
Jim P.Commented:
This an ADP?

Then it would be
 WHERE searchstring LIKE '% 123\_ %' escape '\'
0
 
damirselAuthor Commented:
sorry don't understand your question "ADP?"

this is not working it pops up error message: 'syntax error missing operator...'
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Jim P.Commented:
Is this an Access Data Project connected to a SQL server?

Then the wildcards are percent "%" and  underscore "_".  If this is linked tables then the wildcards are the asterick "*" and question mark "?" and you don't have to worry about the _.
0
 
damirselAuthor Commented:
I am using VB with ADO (Microsoft.Jet.OLEDB.4.0) to connect to mdb.
0
 
Jim P.Commented:
>>I am using VB with ADO (Microsoft.Jet.OLEDB.4.0) to connect to mdb.


Then it is

sSql = sSql + " AND user LIKE '*" & Text1.Text & "*'"
0
 
Jim P.Commented:
From the VB Help:
Wildcard Characters Used in String Comparisons

Built-in pattern matching provides a versatile tool for making string comparisons. The following table shows the wildcard characters you can use with the Like operator and the number of digits or strings they match.

Character(s) in pattern Matches in expression
?       Any single character
*       Zero or more characters
#       Any single digit (09)
[charlist]       Any single character in charlist
[!charlist]       Any single character not in charlist

A group of one or more characters (charlist) enclosed in brackets ([ ]) can be used to match any single character in expression and can include almost any characters in the ANSI character set, including digits. In fact, the special characters opening bracket ([ ), question mark (?), number sign (#), and asterisk (*) can be used to match themselves directly only if enclosed in brackets. The closing bracket ( ]) can't be used within a group to match itself, but it can be used outside a group as an individual character.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.