title: Using fn_Split in SQL query
body: <p>I've been struggling with getting <code>fn_Split</code> to work properly in my query.  I've searched high and low and found answers here that seem close to what I need but I'm still unable to make it work.  </p>
  
  <p>Basically I'm trying to return records that match entries in an array.  I've already got a Table-valued Function working with my database like so: </p>
  
  <pre><code>Select * From dbo.fn_Split('county1, county2',',')
  </code></pre>
  
  <p>My problem is getting it to work in my application where I want it to return records that have either the same exact counties selected or have the selected counties as part of a larger set of counties (say all of them).  The counties are stored in a column called County in the following format: county1, county2, county3 and so on.  I now realize that this is part of the problem and it is bad form to have multiple values in one column but I can't do anything about that now unfortunately.  </p>
  
  <p>So, here's what I've got so far:</p>
  
  <pre><code>SELECT * FROM MyTable WHERE County IN (SELECT County From dbo.fn_Split(@counties, ','))
  </code></pre>
  
  <p>This returns all the records for some reason.  <code>@counties</code> is in the following format: </p>
  
  <p><code>county1, county2</code></p>
  
  <p>Any help would be greatly appreciated.  I'm new to writing SQL so forgive me if I didn't explain this well. Thanks!</p>