Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有多个搜索词的sql查询_Sql_Sql Server_Sql Server 2005_Tsql - Fatal编程技术网

具有多个搜索词的sql查询

具有多个搜索词的sql查询,sql,sql-server,sql-server-2005,tsql,Sql,Sql Server,Sql Server 2005,Tsql,我使用以下查询来获取包含inventoryLocalization表的name列中的某些单词(由函数拆分)的所有数据 在本例中,我拆分了“红-绿-蓝”字符串。 应该是,它返回了所有行,如或运算符 SELECT distinct inL.name FROM dbo.[inventoryLocalization] inL JOIN fnSplitString (N'red green blue',' ' ) words ON (inL.name LIKE '%'+ words.item +'%')

我使用以下查询来获取包含inventoryLocalization表的name列中的某些单词(由函数拆分)的所有数据

在本例中,我拆分了“红-绿-蓝”字符串。 应该是,它返回了所有行,如运算符

SELECT distinct 
inL.name
FROM dbo.[inventoryLocalization] inL
JOIN fnSplitString (N'red green blue',' ' ) words ON (inL.name LIKE '%'+ words.item +'%')

我的问题是,是否可以获取包含所有单词的行,如运算符中的行。

尝试以下操作:

SELECT distinct 
inL.name
FROM dbo.[inventoryLocalization] inL
JOIN fnSplitString (N'red green blue',' ' ) words ON (inL.name LIKE '%'+ words.item +'%')
DECLARE @SomeWords NVARCHAR(200), @Num INT

SET @SomeWords = 'red green blue'

SELECT @Num = COUNT(*)
FROM fnSplitString (@SomeWords,' ')

SELECT inL.name
FROM dbo.[inventoryLocalization] inL
JOIN fnSplitString (@SomeWords,' ' )words 
ON (inL.name LIKE '%'+ words.item +'%')
GROUP BY inL.name
HAVING COUNT(*) = @Num