una consulta sql con varias palabras de búsqueda

i use following query to get all data which contains the some words (which is split by a function) in the nombre column of the inventoryLocalization table.

in the example i have split "red green blue" string. as it should be, it returned all rows like OR operador.

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

My question is, is it possible to get rows which has all words, as in the Y operador.

preguntado el 08 de noviembre de 11 a las 09:11

2 Respuestas

select inL.name from dbo.[inventoryLocalization] inL 
where not exists
    (select 1 from fnSplitString(N'red green blue',' ') words 
    where (inL.name NOT LIKE '%'+ words.item +'%'))

respondido 09 nov., 11:14

Intente algo como esto:

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

respondido 08 nov., 11:16

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.