With
SrcTab As (
Select *
From (values ('Contains x y z')
, ('Contains x and y')
, ('Contains y only')) v (SrcField)),
CharList As ( --< CTE instead of temporary table
Select *
From (values ('x')
, ('y')
, ('z')) v (c))
Select SrcField
From SrcTab, CharList
Group By SrcField
Having SUM(SIGN(CharIndex(C, SrcField))) < 3 --< Count hits
;
如果Distinct
是不可取的,我們只需要檢查計數每行:
With
SrcTab As (--< Sample Data CTE
Select *
From (values ('Contains x y z')
, ('Contains x and y')
, ('Contains y only')
, ('Contains y only')) v (SrcField))
Select SrcField
From SrcTab
Where (
Select Count(*) --< Count hits
From (Values ('x'), ('y'), ('z')) v (c)
Where CharIndex(C, SrcField) > 0
) < 3
;
由於這是一個練習,你應該表現出一些自己的努力,不是嗎? :-)可能有助於搜索'CHARINDEX'返回'0',如果搜索的字符是**不包含在字符串中,否則返回它的位置... – Shnugo
我同意,你需要嘗試一些東西首先你自己,這是學習的最佳方式。您可以通過此頁面上的鏈接找到實現此任務所需的一切:https://msdn.microsoft.com/en-GB/library/ms181984.aspx – Tanner