TSQL - Querying a table column to pull out popular words for a tag cloud

jamesmhaley picture jamesmhaley · Oct 6, 2011 · Viewed 7.3k times · Source

Just an exploratory question to see if anyone has done this or if, in fact it is at all possible.

We all know what a tag cloud is, and usually, a tag cloud is created by someone assigning tags. Is it possible, within the current features of SQL Server to create this automatically, maybe via trigger when a table has a record added or updated, by looking at the data within a certain column and getting popular words?

It is similar to this question: How can I get the most popular words in a table via mysql?. But, that is MySQL not MSSQL.

Thanks in advance. James

Answer

Matthew picture Matthew · Oct 6, 2011

Here is a good bit on parsing delimited string into rows:
http://anyrest.wordpress.com/2010/08/13/converting-parsing-delimited-string-column-in-sql-to-rows/

http://www.sqlteam.com/article/parsing-csv-values-into-multiple-rows

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648

T-SQL: Opposite to string concatenation - how to split string into multiple records

If you want to parse all words, you can use the space ' ' as your delimiter, Then you get a row for each word.

Next you would simply select the result set GROUPing by the word and aggregating the COUNT

Order your results and you're there.