I have the following dataset example:
Name: | Qualities: |
---|---|
Adam | Authentic,Cool,Young |
Bob | Serious,Old,Authentic |
Carl | Cool,Athletic,Hardworker |
And I need to use SQL to turn this dataset into the following:
Name: | Qualities: |
---|---|
Adam | Authentic |
Adam | Cool |
Adam | Young |
Bob | Serious |
Bob | Old |
Bob | Authentic |
Carl | Cool |
Carl | Athletic |
Carl | Hardworker |
Can someone give me a hand on that? I have no clue how can I get this done.
Hope to find it out soon!
Cheers!
CodePudding user response:
SELECT Name, value AS Quality FROM <dataset>
CROSS APPLY STRING_SPLIT(Qualities, ',')
CodePudding user response:
You can used STRING_SPLIT for string values.
Please see more informaton.
https://www.sqlservertutorial.net/sql-server-string-functions/sql-server-string_split-function/
SELECT
Name,
value Quality
FROM
<TABLE NAME>
CROSS APPLY STRING_SPLIT(Qualities, ',');