I am using SQL Server 2005.
I have created a table with the columns ID and Courses. Records are as follows:
ID Courses
1. Java, ASP.Net, C#
2. Java
3. Java, C#
4. html
The Courses column is of type varchar and the values in it are comma separated.
I want to separate every word and store it in another or temp. table.
Output must be like this:
ID Courses
1. Java
2. ASP.Net
3. C#
4. html
Here ID is not important.
Thank you.
see my previous answer to this
this is the best source:
http://www.sommarskog.se/arrays-in-sql.html
create a split function, and use it like:
I prefer the number table approach
For this method to work, you need to do this one time table setup:
Once the Numbers table is set up, create this function:
You can now easily split a CSV string into a table and join on it:
OUTPUT:
To make what you need work, use CROSS APPLY:
OUTPUT: