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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

searching for the [ and ] characters

Status
Not open for further replies.

sdpsc

Technical User
Feb 10, 2001
76
How can I search for [ and ] brackets in a SQL statement? It doesn't work just searching for it like a normal string.
 
But searching for it normally with a select statement doesn't work.
 
could you explain please? what does "searching for it normally with a select statement" mean? could you give an example of the select statement that's not working?

rudy
SQL Consulting
 
There are [ and ] characters in a text field in a database. If I search like this:

select * from table where field like '*[*';

Then it finds nothing.
 
I think you are trying to use LIKE which interprets [ as the start of [] which is used to list characters to match for a single position. If I'm wrong, please post the error message you are getting.

Like "*[abc][hsp]*" -> finds where the field has an a, b, or c immediately followed by an h, s, or p.

To search a field for [ at any position you need to enclose it with square brackets like this:

Where fieldname Like '*[[]*'

To search a field for [ followed by ] use this:

Where fieldname Like '*[[]*[]]*'


John
 
That was it, thanks JonFer!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top