How to use JOIN LIKE with AND Operator in SQL Server? [duplicate]

人盡茶涼 提交于 2020-01-07 06:18:46

问题


Look at this scenario first:

I have table1 with column C1 and 2 records in it with values Text1 and Text2.

SELECT * FROM TabelX
INNER JOIN table1 ON TableX.Name LIKE '%'+table1.C1+'%'

This code means:

SELECT * FROM TabelX
WHERE TableX.Name LIKE '%Text1%' OR TableX.Name LIKE '%Text2%'

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

SELECT * FROM TabelX
WHERE TableX.Name LIKE '%Text1%' AND TableX.Name LIKE '%Text2%'

回答1:


I think something like this can work for you:

BEGIN
declare @mycounter integer
select @mycounter = count (*) from table1

SELECT * FROM TabelX
where @mycounter = (select * from table1 where TableX.Name LIKE '%'+table1.C1+'%')
END


来源:https://stackoverflow.com/questions/39745766/how-to-use-join-like-with-and-operator-in-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!