How to Search Text using Contains Command in SQL Server

For searching a specific word or phrase within a full-text index in SQL Server, use the CONTAINS predicate.

In this tutorial, we will learn How to Search Text using SQL Contains Command in SQL Server.

  • CONTAINS  is the predicate in a WHERE clause that performs a full-text search
  • CONTAINS  – searches for a word or phrase using fuzzy logic

Also check the previous article Find 2nd, 3rd and Nth Highest Salary in SQL SERVER

NEAR: Finds words that are close to one another.

AND: Identifies documents with both search phrases in them.

OR:  Finds records that have either search term in them.

NOT:: Finds documents that do not contain the search term.

Find Text using SQL Contains Command

USE AdventureWorks2019;    
SELECT Name, ListPrice FROM Production.Product  WHERE ListPrice = 539.99  
   AND CONTAINS(Name, 'Mountain');  
  
 Contains Command in SQL Server

In this example, product denotes the name of the table you want to search, Name denotes the name of the column you want to search, and ‘search term’ denotes the term you want to look for.

SELECT Name, Color   
FROM Production.Product  
WHERE CONTAINS((Name, Color), 'Red');
Contains Command in SQL Server

Leave a Reply

Your email address will not be published. Required fields are marked *