Thursday, July 10, 2008

Select statement when table value has square brackets


I had to query a customer table which has customer name enclosed in square brackets.

I tried this first
SELECT * FROM JCustomer WHERE FirstName LIKE '%[%]' -- no rows returned
Then i tried this,
SELECT * FROM JCustomer WHERE FirstName LIKE ' [ [ ]% ' -- this return records which start with square brackets. The trick is to enclose the search string within a square bracket.