I have a table with some columns having multiple values inside separated by comma. I want to split them as new rows. I can obtain correct result if there is only one column involved. But there are several columns with comma separated values to be split all at once. The problem is that the record is multiplying to unnecessary records when I use either
OUTER APPLY dbo.split([columnName], ',')
or
cross apply STRING_SPLIT ([columnName], ',')
in SQL. The same result I am getting when using SSIS. Can someone help me obtain the expected result using SQL or SSIS?
Sample record and expected result:
Note that there are records with values higher than two entries, so comma will be encountered many times.
Current record:
ID Fruit Name Color Taste Price
1 Apple red,green sweet,sour 20,30
Expected result after splitting the comma-delimited values into rows:
ID Fruit Name Color Taste Price
1 Apple red sweet 20
1 Apple green sour 30
What I am getting is:
ID Fruit Name Color Taste Price
1 Apple red sweet 20
1 Apple red sour 30
1 Apple green sweet 20
1 Apple green sour 30