Ilan Ilan - 1 year ago 88
SQL Question

Using values of table in the WHERE clause of SQL query

I have a table with descriptions of a lot of companies.

TABLE dbo.[TblCompanies]
[CompanyID] [int] IDENTITY(1,1) NOT NULL,
[CompanyProfile] [nvarchar](max) NOT NULL

Descriptions look like that

"Agilent Technologies, Inc. provides application focused solutions to

I also have another table that has some strings

TABLE dbo.[TblFilter]
[Pattern] [nvarchar](100) NOT NULL

For example



How can I get
of a all the companies that have ALL the values that are in
in their
? The appearing order of the filter strings in
IS NOT important. What IS important is that ALL these strings will be in the

Would be prefer solution without cursors.


Answer Source

You could filter out rows for which any pattern does not match:

select  *
from    TblCompanies c
where   not exists
        select  *
        from    TblFilter f
        where   c. CompanyProfile not like '%' + f.Pattern + '%'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download