'LIKE' clause with 'AND' operator in SQL Server 2012

I have exactly the same requirement as in this thread. How to use JOIN LIKE with AND Operator in SQL Server?

I have been clueless despite searching the net for hours.

  • How to produce an csv output file from stored procedure in SQL Server
  • Delete All / Bulk Insert
  • Testing custom ORM solution performance overhead - how to?
  • How can I do something like: USE @databaseName
  • Are the elements of an XML alwas ordered if I get them from SQL Server 2012
  • C# batch update to database using Stored Procedure
  • I have a table ‘Filter’ with column ‘Value’ and 2 records in it as ‘Value1’ and ‘Value2’ as varchar values.

    Select * From MasterTable
    Inner Join Filter ON MasterTable.Name LIKE '%' + Filter.Value + '%'
    

    This query means:

    Select * From MasterTable
    Where MasterTable.Name LIKE '%Value1%' OR MasterTable.Name LIKE '%Value2%'
    

    Now how can I change JOIN LIKE that means AND not OR? Something like:

    Select * From MasterTable
    Where MasterTable.Name LIKE '%Value1%' AND MasterTable.Name LIKE '%Value2%'
    

    Can anyone show me a way out.

  • SQL Server CTE -Find top parentID forEach childID?
  • how to detect sql server timeout from .NET application without using catch Exception
  • SQL update from one Table to another based on a ID match
  • displaying reporting weeks
  • Use smo to rename datafiles
  • Can't start sql server in single user mode
  • One Solution collect form web for “'LIKE' clause with 'AND' operator in SQL Server 2012”

    You can generally rewrite a “X matches all Y” query as “X does not have any Y that do not match” – or in other words a NOT EXISTS query for the inverse of Y.

    select *
    from MasterTable
    where not exists (
        select 1
        from Filter
        where MasterTable.Name not like '%' + Filter.Value + '%'
    )
    
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.