如何在SQL Server中将AND和JOIN LIKE一起使用? [英] How to use JOIN LIKE with AND Operator in SQL Server?
本文介绍了如何在SQL Server中将AND和JOIN LIKE一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
先看看这种情况:
我有table1的C1列和2条记录,它们的值分别为Text1和Text2.
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+'%'
此代码表示:
SELECT * FROM TabelX
WHERE TableX.Name LIKE '%Text1%' OR TableX.Name LIKE '%Text2%'
现在如何更改JOIN LIKE,即AND而不是OR?像这样:
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%'
推荐答案
我认为这样的方法可以为您服务:
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
这篇关于如何在SQL Server中将AND和JOIN LIKE一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文