KamilDS KamilDS - 1 year ago 106
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.

Answer Source

You could use an exists criteria:

from Table1 T1
where exists (select T2.value2 from Table2 T2 where T1.value1 like '%'+T2.value2+'%')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download