Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Searching for Words or Phrases Close to Another Word or Phrase (Proximity Term)

SQL Server 2000

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 user close to the word computers.

USE pubs
GO
SELECT title, notes
FROM titles
WHERE CONTAINS (notes, 'user NEAR computers')
GO

However, you can also reverse the words in the WHERE clause to get the same result:

WHERE CONTAINS (notes, 'computers NEAR user')

You can specify the tilde (~) in place of the NEAR keyword in the earlier queries, and get the same results:

WHERE CONTAINS (notes, 'computers ~ user')

More than two words or phase can be specified in the search conditions. For example, it is possible to say:

WHERE CONTAINS (notes, ' hardware ~ softward ~ computer ')

This means that hardware should be in close proximity to software, and software should be in close proximity to computer.

In addition, matching the prefix of a word can be combined with searching for a word or phrase in close proximity to another word or phrase. This example searches for all descriptions in which the description has sauces in close proximity to any form of mix, such as mixing, or mixed.

WHERE CONTAINS(Description, ' sauces ~ "mix*" ')

To find wheat bread mix and also wheatberry bread mix, you could use this type of search:

WHERE CONTAINS(Description, ' "wheat*" ~ "bread mix" ')

See Also

CONTAINS

WHERE

Show:
© 2015 Microsoft