Escaping Bracket [ in a CONTAINS() clause?

How can I escape a bracket in a full-text SQL Server contains() query? I've tried all the following, none of which work:

CONTAINS(crev.RawText, 'arg[0]')
CONTAINS(crev.RawText, 'arg[[0]]')
CONTAINS(crev.RawText, 'arg\[0\]')

Using double quotes does work, but it forces the entire search to be a phrase, which is a showstopper for multiple word queries.

CONTAINS(crev.RawText, '"arg[0]"')

All I really want to do is escape the bracket, but I can't seem to do that..

Answers


You don't have to escape the [ as it has no special meaning in Full Text Search. If you do need to search for an exact match though, you can use "" marks.

Further, you can use multiple "" inside the single quotes:

CONTAINS('"word1" or "word2" or "word3"')

This also works:

CONTAINS('"word1" and "word2" and "word3"')

Anything put inside the double quotes is treated as exact text. Thus if I were to do a search of the Description field of the Production.ProductDescription table in AdventureWorks, I could use

CONTAINS('shifting and "on or off-road"')

and it would find matches for the word shifting that also had the phrase "on or off-road".

The only special symbol is the ~, it can be used in place of the NEAR command.

CONTAINS('shifting ~ smooth')

is the same as

CONTAINS('shifting NEAR smooth')

and will find matches where the words shifting and smooth are near each other.


Need Your Help

gmail inbox actions are exclusive?

javascript html gmail inbox

This question may get negative to oblivion as I don't know how important this is. But I made a fast search and couldn't find anything about other major e-mail providers developing those inbox actio...

How to manage many schemas on one database using hibernate

spring hibernate sql-server-2005 schema

I have one database that has many schemas, one per client. We want to create a web application to be access online by the clients, the application should get the schema on runtime, I think in use

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.