X

Quick tip on SQL Server square bracket search

SQL

Here is a quick tip, when you are searching for a text that contains square brackets “[]” in Microsoft SQL Server. For example you are searching for a text that contains “text text text [text] text text”. A simple query using LIKE % would not do the trick.
One has to add double square brackets to search for the square bracket text.

Example

Select * from Employee where Status like '[Part-Time]'

The previous query will not return any match items. But if you replace the query with double brackets like

Select * from Employee where Status like '[[Part-Time]'

or 
Select * from Employee where Status like '[[]Part-Time]'

The above will return you data that match the square bracket text.

Categories: sql
Tags: sqltip
Taswar Bhatti: