Is Contains Equivalent To Like In SQL Server

僤鯓⒐⒋嵵緔 提交于 2019-12-01 08:53:38

You need to use an asterisk to perform a prefix search:

WHERE CONTAINS(Column1 , ' "a*" ');
WHERE CONTAINS(Column1 , ' "A*" ');

In addition to this, CONTAINS is subject to stopword filters. Read up on those here

A stopword can be a word with meaning in a specific language, or it can be a token that does not have linguistic meaning. For example, in the English language, words such as "a," "and," "is," and "the" are left out of the full-text index since they are known to be useless to a search.

To pass input as a parameter, just append the asterisk:

declare @SearchThis varchar(10) = 'A'; 
set @SearchThis = quotename(@SearchThis + '*', '"');
select @SearchThis;

Once you have the SearchThis setup, you can use in where:

WHERE CONTAINS(Column1, @SearchThis)

CONTAINS is much more powerful than LIKE. From MSDN...

Comparison of LIKE to Full-Text Search

In contrast to full-text search, the LIKE Transact-SQL predicate works on character patterns only. Also, you cannot use the LIKE predicate to query formatted binary data. Furthermore, a LIKE query against a large amount of unstructured text data is much slower than an equivalent full-text query against the same data. A LIKE query against millions of rows of text data can take minutes to return; whereas a full-text query can take only seconds or less against the same data, depending on the number of rows that are returned and their size. Another consideration is that LIKE performs only a simple pattern scan of an entire table. A full-text query, in contrast, is language aware, applying specific transformations at index and query time, such as filtering stopwords and making thesaurus and inflectional expansions. These transformations help full-text queries improve their recall and the final ranking of their results.

For your specific concern, you need the prefix search that other answers indicate. But head to the MSDN page that I linked. It will help you out.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!