I have a table that lists a freet text input from a survey where enterents were allowed to enter their responses (regarding colours they would like to have in their wedding)
DECLARE @phrases TABLE (id int, phrase varchar(max))
INSERT @phrases values
(1,'Red and White' ),
(2,'green' ),
(3,'White and blue' ),
(4,'Blue' ),
(5,'Dark blue' );
SELECT word, COUNT(*) c
FROM @phrases
CROSS APPLY (SELECT CAST(''+REPLACE(phrase,' ','')+'' AS xml) xml1 ) t1
CROSS APPLY (SELECT n.value('.','varchar(max)') AS word FROM xml1.nodes('a') x(n) ) t2
GROUP BY word
word freq ----------- ----------- and 2 blue 3 Dark 1 green 1 Red 1 White 2