在Sql server中传递Contains()中的特殊字符

时间:2013-06-17 09:37:51

标签: sql-server

我的表名称产品包含所有产品详细信息。(列:ID,名称,价格)

产品名称为“Garminnüvi1340TGPS for Europe 4.3”屏幕,Info Traffic TMC Premium,Micro SD Card“来自链接”

我想在sql server中使用contains()搜索此产品。

我写了查询

select top 10 * from Product where CONTAINS(p.*,N'((((((((((((((FORMSOF (INFLECTIONAL, Garmin) AND FORMSOF (INFLECTIONAL, nüvi)) AND FORMSOF (INFLECTIONAL, 1340T)) AND FORMSOF (INFLECTIONAL, GPS)) AND FORMSOF (INFLECTIONAL, for)) AND FORMSOF (INFLECTIONAL, Europe))  AND FORMSOF (INFLECTIONAL, 4.3)) AND FORMSOF (INFLECTIONAL, screen)) AND FORMSOF (INFLECTIONAL, Info)) AND FORMSOF (INFLECTIONAL, Traffic)) AND FORMSOF (INFLECTIONAL, TMC)) AND FORMSOF (INFLECTIONAL, Premium)) AND FORMSOF (INFLECTIONAL, Micro)) AND FORMSOF (INFLECTIONAL, SD)) AND FORMSOF (INFLECTIONAL, Card))')

这显示零结果。

我试过“(双引号)和(分号)查询服务错误。

删除那两个特殊字符。所以它没有显示任何结果。

如何传递特殊字符或如何使用特殊字符进行搜索。

提前致谢

1 个答案:

答案 0 :(得分:1)

我建议使用N'((((而不是'((((就像你将它转换为nvarchar而不是varchar。

另一件事是检查“for” - for是一个普通的关键字,因此在创建全文索引时被跳过;这个查询(实验性地)适合我

N'((((((((((((((FORMSOF (INFLECTIONAL, Garmin) AND FORMSOF (INFLECTIONAL, nüvi)) AND FORMSOF (INFLECTIONAL, 1340T)) AND FORMSOF (INFLECTIONAL, GPS))) AND FORMSOF (INFLECTIONAL, Europe))  AND FORMSOF (INFLECTIONAL, 4.3)) AND FORMSOF (INFLECTIONAL, screen)) AND FORMSOF (INFLECTIONAL, Info)) AND FORMSOF (INFLECTIONAL, Traffic)) AND FORMSOF (INFLECTIONAL, TMC)) AND FORMSOF (INFLECTIONAL, Premium)) AND FORMSOF (INFLECTIONAL, Micro)) AND FORMSOF (INFLECTIONAL, SD)) AND FORMSOF (INFLECTIONAL, Card))