How to deal with queires which contain square brackets?

  • Thread starter Thread starter Peijun
  • Start date Start date
P

Peijun

I have to search my database with a query containing square brackets. How can
I escape it?

Thanks in advance,

Peijun Zhang
 
Hi,

Try any of these:

Opening bracket:

select * from tblSomeTable where SomeField like "*[[]*";

Closing bracket:

select * from tblSomeTable where SomeField like "*]*";

Opening bracket followed by a closing bracke:

select * from tblSomeTable where SomeField like "*[[]*]*";

Clifford Bass
 
I assume you are referring to the brackets around object names. If you've
included spaces or other special characters in table or column names then
these have to be wrapped in square brackets when referenced in a query of
code. You can avoid this by not including such characters when creating the
table definitions, e.g. instead of a column named [Last Name] use LastName or
Last_Name. Also avoid using terms such as Date or Name as a column name, as
the first is the name of a built in function, the second of a property; use
something more specific such as TransactionDate or CompanyName.

Ken Sheridan
Stafford, England
 
Back
Top