title: Reverse to STRING_AGG
body: <p>Here is a sample data on which we are further processing.</p>
  <pre><code>create table #tmp (id int identity(1,1), na varchar(10),me varchar(10))
  insert into #tmp (na,me)
  values 
  ('a','t'),
  ('a','u'),
  ('a','v'),
  ('a','w'),
  ('b','x'),
  ('b','y'),
  ('b','z')
  select * from #tmp
  </code></pre>
  <p>My question is, is there any exact reverse of the <code>STRING_AGG</code> function for SQL Server?</p>
  <p>Like I am merging using <code>STRING_AGG</code> with the following code</p>
  <pre><code>select na, STRING_AGG(me,',') as me into #tmp1 from #tmp group by na
  select * from #tmp1
  </code></pre>
  <p>I need to reverse the process but I had to use CURSOR so I am searching for an alternative solution.</p>
  <p>Below is the cursor code for better understanding the purpose.</p>
  <pre><code>declare @na varchar(10)
  declare @me varchar(max)
  create table #tmp3 (na varchar(10),me varchar(10))
  
  declare dbc cursor for select na, me from #tmp1
  open dbc
  
  while 1=1
  begin
      fetch next from dbc into @na, @me
  
      if @@FETCH_STATUS &lt;&gt; 0
          break;
  
      insert into #tmp3 (na,me)
      select @na, value
      from string_split(@me,',')
      
  end
  
  close dbc
  deallocate dbc
  
  select * from #tmp3
  
  --Delete temp table
  
  drop table #tmp
  drop table #tmp1
  drop table #tmp3
  </code></pre>