Searching for Words or Phrases Close to Another Word or Phrase (Proximity Term)
You can search for words or phrases in close proximity to another word or phrase. In addition, you can specify two words or phrases in any order and get the same result. This example searches for the word "reflector" close to the word "bracket".
USE AdventureWorks;
GO
SELECT DocumentID, DocumentSummary, Document
FROM Production.Document AS DocTable INNER JOIN
CONTAINSTABLE(Production.Document, Document, '(Reflector NEAR Bracket)' ) AS KEY_TBL
ON DocTable.DocumentID = KEY_TBL.[KEY]
ORDER BY KEY_TBL.RANK;
GO
Notice that you can also reverse the terms in CONTAINSTABLE to get the same result:
CONTAINSTABLE(Production.Document, Document, '(Bracket NEAR Reflector)' ) AS KEY_TBL
You can use the tilde character (~) in place of the NEAR keyword in the earlier query, and get the same results:
CONTAINSTABLE(Production.Document, Document, '(Reflector ~ Bracket)' ) AS KEY_TBL
More than two words or phrases can be specified in the search conditions. For example, it is possible to say:
CONTAINSTABLE(Production.Document, Document, '(Reflector ~ Bracket ~ Installation)' ) AS KEY_TBL
This means that "Reflector" should be in close proximity to "Bracket", and "Bracket" should be in close proximity to "Installation".
See Also
Concepts
Other Resources
CONTAINS (Transact-SQL)
WHERE (Transact-SQL)