title: Comma separated values count
body: <p>Table Pattern has single column with the following values:</p>
  
  <pre><code>NewsletteridPattern
  ------------
  %50%
  %51%
  </code></pre>
  
  <p>Table B has the following values:</p>
  
  <pre><code>SubscriberId NewsletterIdCsv
  ------------ -----------------
  47421584     51
  45551047     50,51
  925606902    50
  47775985     51    
  </code></pre>
  
  <p>I have the following query which basically counts the comma seperated values by using the pattern:</p>
  
  <pre><code>SELECT *
  FROM TABLEB t WITH (nolock)
  JOIN Patterns p ON (t.NewsletteridPattern LIKE p.pattern)
  </code></pre>
  
  <p>The problem is that the count is incorrect as for example my pattern has %50% and %51% and thus the row number 2 from Table B should be counted twice, however with my query it is only once, how do I fx that?</p>
  
  <p><strong>EDIT :</strong><br>
  I forgot to add DISTINCT in my original query which was causing the issue:</p>
  
  <pre><code>SELECT Count(Distinct Subscriberid)
  FROM TABLEB t WITH (nolock)
  JOIN Patterns p ON (t.NewsletteridPattern LIKE p.pattern)
  </code></pre>