title: split comma separated values into distinct rows
body: <p>I have a table which looks like this:</p>
  
  <pre><code>id  fk_det  userid
  3   9   name1,name2
  6   1   name3
  9   2   name4,name5
  12  3   name6,name7
  </code></pre>
  
  <p>I have already learned to regret having the values of the userid in comma separated values, so i want to split the rows up and end up with something that looks like</p>
  
  <pre><code>id  fk_det  userid
  3   9   name1
  x   9   name2
  6   1   name3
  9   2   name4
  x   2   name5
  12  3   name6
  x   3   name7
  </code></pre>
  
  <p>i had been looking at something like this:</p>
  
  <pre><code>select fk_det, det, LEFT(userid, CHARINDEX(',',userid+',')-1),
      STUFF(userid, 1, CHARINDEX(',',userid+','), '')
  from global_permissions
  </code></pre>
  
  <p>but i'm not sure how to make it work when userid contains more than 2 items (which it might, some might have none, some might have multiple, just depends)</p>