KamilDS KamilDS - 1 month ago 3x
SQL Question

SQL Server : delete where string value contains another value

I want to delete from table all records which selected string value contains in another value from another table (with ignore case sensitive).

For example: if

(from one table) and
value2-"Hello word"
(from another table), then that record should be deleted.

DELETE FROM [table1]
WHERE value1 LIKE '%' + (SELECT value2 FROM [table2]) + '%'

But that SQL statement returns an error.


You could use an exists criteria:

from Table1 T1
where exists (select T2.value2 from Table2 T2 where T1.value1 like '%'+T2.value2+'%')