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

后端 未结 1 772
南旧
南旧 2021-01-26 07:32

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.

1条回答
  •  走了就别回头了
    2021-01-26 08:29

    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 + '%'
    )
    

    0 讨论(0)
提交回复
热议问题