How to do SQL Server CONTAINS full text search for 'C #'

In SQL Server 2008 R2, I am doing a full text search for the term "C #" like this:

SELECT *
FROM  Book b  
WHERE CONTAINS (b.title , 'c#')

      

However, a full text search looks like it strips out the pound sign and then does the search.

If I do the "as" wildcard, I get the correct results:

SELECT *
FROM  Book b  
where title like '%c#%'

      

Is there a way to do a full text search CONTAINS

for an expression that contains a hash / pound sign?

+3


source to share


2 answers


It looks like full text search does exactly what it was supposed to do. To match exactly, modify the where clause C#

to enclose the term in double quotes. Since exact matching is case sensitive by definition, you can use or to search in both lowercase and uppercase versions.



WHERE CONTAINS(Name, '"C#" or "c#"');

      

+1


source


I don't have a sandbox to test this, but have you tried CHAR(35)

which is the pound icon? You can set a variable and concatenate it with CHAR(35)

that may work.



0


source







All Articles