2017-07-20 1 views
1

VARCHAR(MAX)のテキストブロブを検索する簡単な検索ツールを実行するためのレポートを作成しています。私はユーザーが2つの異なる検索タイプを選択できるようにしようとしています:すべての検索用語を含み、任意のものを含みます。私は、Contains allとContains anyの間で変更するための構文を見つけるのが難しいです。以下は私がそれが働く方法の要点です。助けてくれてありがとう!Transact-SQLでは、Contains allとContainsの間でどのようにパラメータを使用するかを変更しますか

Where Reprt.DateStamp >= @StartDate and Reprt.DateStamp <= @EndDate and 
IF @SearchType = 'And' 
     Reprt.ContentText like '%'[email protected]+'%' and 
     Reprt.ContentText like '%'[email protected]+'%' and 
     Reprt.ContentText like '%'[email protected]+'%' and 
     Reprt.ContentText like '%'[email protected]+'%' 
Else 
     Reprt.ContentText like '%'[email protected]+'%' or 
     Reprt.ContentText like '%'[email protected]+'%' or 
     Reprt.ContentText like '%'[email protected]+'%' or 
     Reprt.ContentText like '%'[email protected]+'%' 
+1

タイプミス申し訳ありません意味さトランスまたはTransact-SQL –

答えて

2

使用AND/ORロジック

Where Reprt.DateStamp >= @StartDate and Reprt.DateStamp <= @EndDate and 
((@SearchType = 'And' and 
     Reprt.ContentText like '%'[email protected]+'%' and 
     Reprt.ContentText like '%'[email protected]+'%' and 
     Reprt.ContentText like '%'[email protected]+'%' and 
     Reprt.ContentText like '%'[email protected]+'%') 
or (@SearchType <> 'And' 
     Reprt.ContentText like '%'[email protected]+'%' or 
     Reprt.ContentText like '%'[email protected]+'%' or 
     Reprt.ContentText like '%'[email protected]+'%' or 
     Reprt.ContentText like '%'[email protected]+'%')) 
+0

またはセクションのために私は追加する必要がありました 'と('後「と」が、それは完全に感謝を動作すること以外に君は! –

関連する問題