title: Most succinct way to transform a CSV string to a table in T-SQL?
body: <pre><code>-- Given a CSV string like this:
  
  declare @roles varchar(800)
  select  @roles = 'Pub,RegUser,ServiceAdmin'
  
  -- Question: How to get roles into a table view like this:
  
  select  'Pub'
  union
  select  'RegUser'
  union
  select  'ServiceAdmin'
  </code></pre>
  
  <hr>
  
  <p>After posting this, I started playing with some dynamic SQL. This seems to work, but seems like there might be some security risks by using dynamic SQL - thoughts on this?</p>
  
  <pre><code>declare @rolesSql varchar(800)
  select  @rolesSql = 'select ''' + replace(@roles, ',', ''' union select ''') + ''''
  exec(@rolesSql)
  </code></pre>