在sql server中使用contains() [英] Use of contains() in sql server

查看:673
本文介绍了在sql server中使用contains()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表名产品包含3列:

 产品编号
名称
价格

名称列中,所有产品名称都存在。



示例:1340 GPS,1340T GPS等。

当我写下

 时,从包含(名称,'1340'); 

结果1行 1340 GPS



但是当我搜索时

 从产品中选择top 10 * %1340%'; 

然后结果是 1340 GPS和1340T GPS

实际上,我的要求是使用 contains(),但它必须显示两行像 LIKE 运算符。



如何做:?

请帮助



提前致谢

解决方案

去做这个 。你可以在包含与like运算符相同的语法之前使用*。但是您需要在搜索字符串之前和之后使用双引号。请检查以下查询:

  SELECT * 
FROM product
WHERE CONTAINS(name,'* 1340 * ');

它一定会起作用。

I am having a table name Product contains 3 columns as:

Product-id
name
Price

In name column, all product names are present.

Example: 1340 GPS, 1340T GPS etc.

When I write

select top 10 * from product where contains(name,'1340');

Result 1 row 1340 GPS

but when I search

select top 10 * from product where name like '%1340%';

Then the result is 1340 GPS and 1340T GPS.

Actually my requirement is I will use contains() but it has to show both the rows like LIKE operator.

How to do so :?

Please help

Thanks in advance

解决方案

Here is straight way to do this . you can use "*" before in contain syntax same as like operator . but you need to use double quote before and after the search string . check following query :

SELECT *
FROM product
WHERE CONTAINS(name,'"*1340*"');

it will definitely work .

这篇关于在sql server中使用contains()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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