Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ProEdge
Yak Posting Veteran
64 Posts |
Posted - 2006-05-25 : 12:52:21
|
| Does anyone know of a way of counting the number of words in a text field using SQL? Thanks |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-05-25 : 13:15:06
|
| How do u define "Words" ?Any set of character(s) seperated by spaces ?How about punctuations brackets etc ?Once u define the "Word",U may be able to find a function (if u dig this forum)Srinika |
 |
|
|
ProEdge
Yak Posting Veteran
64 Posts |
Posted - 2006-05-25 : 14:00:30
|
| Yes by words I do mean a set of character(s) separated by spaces. Example: Batman Part II |
 |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-05-25 : 14:58:27
|
quote: Originally posted by ProEdge Example: Batman Part II
How many words in it 2 or 3how many words in the following :1. www.google.com2. How many < more > words in this3. How many words here Srinika |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2006-05-25 : 15:51:31
|
| [code]CREATE FUNCTION udf_Word_Count (@str varchar(8000), @word varchar(255))RETURNS intASBEGIN DECLARE @DelimFound int, @LastDelimPosition int, @Count int SELECT @DelimFound = 0, @LastDelimPosition = 0, @Count = 0 WHILE (@DelimFound <= LEN(@str)) BEGIN IF (CHARINDEX(@Word, @str, @LastDelimPosition + 1) = 0) BREAK ELSE BEGIN SET @Count = @Count + 1 SET @LastDelimPosition = CHARINDEX(@Word, @str, @LastDelimPosition + 1) END END RETURN @Count END[/code]Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
ProEdge
Yak Posting Veteran
64 Posts |
Posted - 2006-05-25 : 15:55:19
|
| X002548, thanks for that. I'll try it out and if I have problems, I'll let you know. |
 |
|
|
sshelper
Posting Yak Master
216 Posts |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
|
|
|
|
|
|
|