使用SQL Server 2014和以下数据:
ID Address City State
1 55 Main St Dallas TX
2 4 Elm Blvd Cupertino CA
3 66 Walnut Miami FL
4 21 Main Ave Cupertino CA
我试图跨多个列使用包含查询来查找匹配项,但无法找到正确的语法。在本例中,我有查询部分:
CONTAINS ((Address, City, State), '"main" or "cupertino")
返回行#1、#2和amp#4.
我也可以试试这个:
CONTAINS ((Address, City, State), '"main" and "cupertino")
这不会返回任何行。
不过,我想知道的是,如何使用包含查询,使用搜索词“main”和“cupertino”返回第4行。
因此,基本上,我尝试使用contains查询执行以下操作:
WHERE (Address LIKE '%main%' OR City LIKE '%main%' OR Zip LIKE '%main%') AND (Address LIKE '%cupertino%' OR City LIKE '%cupertino%' OR Zip LIKE '%cupertino%')