2016-09-28 92 views
0

先看看這個場景:如何在SQL Server中使用JOIN LIKE和AND運算符?

我有table1與列C1和2個記錄在它的值爲Text1和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類似的手段,而不是OR?喜歡的東西:

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

我問過同樣的問題,得到了[@lc]答案(http://stackoverflow.com/用戶/ 44853/LC)。你可以參考下面的線程。 http://stackoverflow.com/questions/39825906/like-clause-with-and-operator-in-sql-server-2012 –

回答

0

我覺得像這樣可以爲你工作:

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

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