问题
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