title: SQL Server 2008 R2: Prepare dynamic WILDCARD
body: <p>I have the following table <code>Test_01</code> with two columns namely <code>Cola</code> and <code>Colb</code>.</p>
  
  <p>I have a situation were I need to use <code>LIKE</code> with <code>IN</code> for multiple values.</p>
  
  <p><strong>Table</strong>:</p>
  
  <pre><code>SELECT * FROM Test_01;
  
  Cola    Colb 
  ------------
  1       A
  11      B
  22      C
  </code></pre>
  
  <p><strong>Example</strong>:</p>
  
  <pre><code>DECLARE @a VARCHAR(max) = 'A,B,C'
  DECLARE @sql VARCHAR(max) = ''
  </code></pre>
  
  <p><strong>My bad try</strong>: Which does not works</p>
  
  <pre><code>SET @SQL = 'SELECT * from test_01 
          WHERE Colb LIKE IN (''%'+REPLACE(@a,',','%'',''%')+'%'')';
  PRINT(@sql);
  </code></pre>
  
  <p>Finally I came to know that I need to prepare a <code>LIKE</code> with <code>OR</code> condition by referring <a href="https://stackoverflow.com/questions/1865353/combining-like-and-in-for-sql-server">THIS</a>.</p>
  
  <p>How to prepare a dynamic WILDCARD as shown it below?</p>
  
  <pre><code>SELECT * FROM Test_01
  WHERE 
  Colb LIKE '%A%' OR 
  Colb LIKE '%B%' OR 
  Colb LIKE '%C%' ; 
  </code></pre>