0

I have a table with one column comma delimited like:

     Col1  Col2
 Row1    1    1,2,3,4
 Row2    2    5,6,7,8

I would like to split the rows by inserting the records into additional columns in @table and have:

    Col1 Col2 Col3 Col4  Col5
Row1    1      1    2    3    4
Row2    2      5    6    7    8

Please assist.

Yogesh Sharma
  • 49,870
  • 5
  • 26
  • 52
tmndungu
  • 320
  • 4
  • 17
  • 4
    Will it always be 4 parts? – Thom A Jan 24 '19 at 13:37
  • No, it will not always be 4 parts, that can vary – tmndungu Jan 24 '19 at 13:39
  • The data comes from an import file, the first row will have the titles eg A,B,C,D,E and they can be between 3 - 40 of them. The no. of titles always matches the no. of expected columns. So I need to first count the titles, create temp table with titles, then split the delimited records into columns and insert into table. – tmndungu Jan 24 '19 at 13:51
  • While I agree this is a duplicate I would avoid most of the answers provided. Looping to split strings is a bad approach. [Here](https://sqlperformance.com/2012/07/t-sql-queries/split-strings) are many better solutions. – Sean Lange Jan 24 '19 at 14:22

0 Answers0