I've got a table which has entries like
id keywords
1 cat, dog, man, mouse
2 man, pen, pencil, eraser
3 dog, man, friends
4 dog, leash,......
I want to make a table something like
id cat dog man mouse pen pencil eraser friends leash ......
1 1 1 1 1 0 0 0 0 0
2 0 0 1 0 1 1 1 0 0
3 0 1 1 0 0 0 0 1 0
and so on.
Gives
Must you use the pivot form? And is your end result the frequency per id - which seems strange? Otherwise the cells always contain 1 as frequency.
See if this works for you.
Sample data
Query
Output
If you are using SQL Server 2008, you can use the full-text parser to split your string:
However, if you are not using SQL Server 2008, then you need a split function. I've presented on at the end of this post. Then your query is simply:
And the split function: