0

Consider a column names MyCol with a full-text index. We want to find those rows that have a value of |foo|.

Tried this, but doesn't find those with exactly |foo|:

SELECT * FROM MyTable WHERE CONTAINS(MyCol,'"|foo|"')

It returns anything with foo. It seems as if pipes are disregarded as separators.

How can I escape, or otherwise ensure that the exact string |foo| is found?

p.campbell
  • 98,673
  • 67
  • 256
  • 322

1 Answers1

2

Escape with:

SELECT * FROM MyTable WHERE CONTAINS(MyCol,'[|]foo[|]')

I think this works too:

SELECT * FROM MyTable WHERE CONTAINS(MyCol,'||foo||') ESCAPE '|'

Oops, this is full-text search. According to this question/answer, there is no way!:

sql-server-full-text-search-escape-characters

Community
  • 1
  • 1
ypercubeᵀᴹ
  • 113,259
  • 19
  • 174
  • 235