0

For Sql Server 2014, what syntax do I need, if this is even possible? (in pseudo-code)

DECLARE @searchstring nvarchar(20)
LOOP @searchstringstring = (SELECT keyword FROM table1)
SELECT column FROM table2 where column LIKE '%@searchstring%'
END LOOP

I want it to return all columns in a single table.

1 Answers1

1

Unless I'm missing something, you want to select all the values in table2.Column that contains the text in table2.Keyword. This can be done easily with a simple inner join:

SELECT t2.column
FROM table2 t2
INNER JOIN table1 t1 ON(t2.column LIKE '%'+ t1.keyword +'%'

Sql works best with set based operations. looping is rarely the desired approach.

Zohar Peled
  • 79,642
  • 10
  • 69
  • 121