I need to query a table with the following words:
"Today was a rainy day"
I need to search for any of these words. For example if you found the word "day" , you would have to return the record. That is, any of those words that I think he would have to return to me.
I also need to do a search that returns all these searched words for example:
"Rainy day today"
If the record in this table has these three words, it does not necessarily have to be in that order.
I'm breaking my head how to do this. Oh I can not use FUllText
because I would have to ask for authorization until PAPA because this feature is disabled in Production. I am using SQL SERVER 2008 R2.
Thanks for the replies I was able to make some progress, I did more or less creating a temporary table to play my search string and separated the words by space. but I'm still in trouble
SET NOCOUNT ON
DECLARE @ARRAY VARCHAR(8000), @DELIMITADOR VARCHAR(100), @S VARCHAR(8000)
-- VALORES PASSADOS PARA A VARIAVEL @ARRAY
SELECT @ARRAY = 'hoje o dia ficou chuvoso'
-- SETANDO O DELIMITADOR
SELECT @DELIMITADOR = ' '
IF LEN(@ARRAY) > 0 SET @ARRAY = @ARRAY + @DELIMITADOR
CREATE TABLE #ARRAY(ITEM_ARRAY VARCHAR(8000))
WHILE LEN(@ARRAY) > 0
BEGIN
SELECT @S = LTRIM(SUBSTRING(@ARRAY, 1, CHARINDEX(@DELIMITADOR, @ARRAY) - 1))
INSERT INTO #ARRAY (ITEM_ARRAY) VALUES (@S)
SELECT @ARRAY = SUBSTRING(@ARRAY, CHARINDEX(@DELIMITADOR, @ARRAY) + 1, LEN(@ARRAY))
END
-- Qualquer uma das palavras
SELECT DISTINCT * FROM TABELA_A a JOIN #ARRAY ON CAMPO1 like '%' + ITEM_ARRAY + '%';
DROP TABLE #ARRAY
SET NOCOUNT OFF
In this example it returns any of the words that are in my temporary table Until then OK. But it confuses the word (day by diagnosis) this in function of the use of Like. But I do not know how to replace it. Moreover, I could not return ONLY the records that contain all the words that are in the temporary table.
They are two things. First: Return any of the words that are in the temporary table Second: Return all words that are in the temporary table
I'm basically taking TABLE A (TEMPORARY) and comparing it to table B and returning the records of table B according to the criteria I've spoken