1

I have a table with values like this.

PK   Values
1    abc,def,ghy,tyu
2    qwe,tyu,iop,fgt

I want to split the CSV and make a new table like this

Id    Value
1     abc
1     def
1     ghy
1     tyu
2     qwe
2     tyu
2     iop
2     fgt

I already have split function but i need a query to align the values with corresponding PK

s7h
  • 51
  • 3
  • I found it fairly easy to take one of the answers in the duplicate link, change the table and columns names, and get your expected output. Next time you should share the query you have tried. – Tim Biegeleisen May 24 '18 at 05:19

1 Answers1

0

try this:

Select t.Id,f.SplitData AS Value from #MyTable t
CROSS APPLY dbo.fnSplitString([Values],',') f
Sahi
  • 1,454
  • 1
  • 13
  • 32