I was able to find information on how to separate a comma delineated strings into columns here: How Do I Split a Delimited String in SQL Server Without Creating a Function? - but it doesn't quite solve my problem.
The data I am working with is a list of interests/activities for a given record. For instance, a record would have 'yoga, hiking' etc... At present we have 63 distinct activities total but we also need to accommodate for activities that do not yet exist.
What I've been tasked with is creating an automated process which:
- Creates a new column in the table for each activity listed (and creates new columns as presently non-existent activities are added)
- Have the columns reflect the name of the activity
- If the record contains an activity, the column for that activity has a Y in it.
Ultimately, the outcome would look something like this...
id | activities | art | yoga | music | hiking | ...
-----------------------------------------------------------
1 | yoga, hiking | NULL | y | NULL | y | ...
2 | art, music, yoga | y | y | y | NULL | ...
Thank you in advance for any help that can be provided, let me know if any more information is required.