SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Count Individual Words in freetext fields


Count Individual Words in freetext fields

Author
Message
Neuro
Neuro
SSChasing Mays
SSChasing Mays (609 reputation)SSChasing Mays (609 reputation)SSChasing Mays (609 reputation)SSChasing Mays (609 reputation)SSChasing Mays (609 reputation)SSChasing Mays (609 reputation)SSChasing Mays (609 reputation)SSChasing Mays (609 reputation)

Group: General Forum Members
Points: 609 Visits: 239

Intresting bit of help required would prefer to do this in SQL especially as now one is working on the server.

I have a table(activity) with 2 fields (RowId,notes)

What I want is a count on all the unique words in the notes field

so for example

rowid

x11102 =This is the first test

x11103 =This is the Second test

------------------

Id want my result set like

Word Count

-----------------

This 2

is 2

the 2

First 1

Test 2

Second 1

Any help would be much appreciated





Wayne Lawton
Wayne Lawton
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1598 Visits: 22

A simple, brute force strategy would be to write a parser to read each NOTES and split the words into a single vertical table. Then simply run a count for each of the distinct words in the vertical table. An alternative implementation is to have two columns in the vertical table (WORD and COUNT) and just update count if the word already exists.

The same results can be achieved by using one of the "split" functions available on this site inside of a derived subquery.

Have a good day

Wayne





Adam Machanic
Adam Machanic
SSCertifiable
SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)

Group: General Forum Members
Points: 6983 Visits: 735
The problem with most split functions is that they can handle only a single character, e.g. ',' -- I think you would have to modify it to handle a pattern instead, so that you could consider all punctuation, white space, etc, characters.

--
Adam Machanic
whoisactive
Adam Machanic
Adam Machanic
SSCertifiable
SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)

Group: General Forum Members
Points: 6983 Visits: 735
Okay, I just posted a UDF to help solve this problem:

http://sqljunkies.com/WebLog/amachanic/articles/PatternSplitString.aspx

... To use it for this problem, you would have to cursor/loop through the table for each row you want, insert the words into a temp table, and then take the final count from there. I'm not aware of a set-based way to handle the problem.

--
Adam Machanic
whoisactive
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search