在SQL Server中包含等同于 [英] Is Contains Equivalent To Like In SQL Server

查看:107
本文介绍了在SQL Server中包含等同于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行此查询时:

Select * from Table1 Where Column1 Like 'aaa%' --3 Result
Select * from Table1 Where Column1 Like 'a%' --3 Result
Select * from Table1 Where Column1 Like 'A%' --3 Result

但是当我跑步时

Select * from Table1 Where Contains(Column1 ,'aaa') --3 Result
Select * from Table1 Where Contains(Column1 ,'a') --0 Result
Select * from Table1 Where Contains(Column1 ,'A') --0 Result

包含可以搜索:按照MSDN


  1. 单词或短语。

  2. 单词或短语的前缀。

  3. 单词

这是否意味着包含不能搜索

如果是,那么如何?

Edit2:

declare @param as varchar(20)='a'
select * from table1 where Contains(column1,@param)

这正在工作,

declare @param as varchar(20)='"a*"'
select * from table1  where Contains(column1,@param)

但是,这不是

declare @param as varchar(20)='a'
select * from table1  where Contains(column1,@param+'*')

然后,

select * from table1  where Contains(column1,'"'+@param+'*"')


推荐答案

您需要使用星号来执行前缀搜索:

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, and, is和 the之类的词被全文索引遗漏了
,因为它们被认为是对
a搜索无用。

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;

有了SearchThis设置后,您可以在以下位置使用

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

WHERE CONTAINS(Column1, @SearchThis)

这篇关于在SQL Server中包含等同于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆