Solved

I want to count the total number of characters in a single column in SQL SERVER

Posted on 2008-10-23
4
792 Views
Last Modified: 2012-05-05
I have a User table. I wish to calculate the total number of words in the user description column. For e.g. if in a user table I have user id=1 , Username=gurbir, User description='testing'. Now I want a program or method through which I can count the total number of words in the description column. Kindly suggest?
0
Comment
Question by:Gurbirs
  • 3
4 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 22784979
are words separated by blanks?
0
 
LVL 7

Expert Comment

by:Norush
ID: 22784989
SELECT     { fn LENGTH(FieldName) } AS LengthOfFieldName
FROM         TableName
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 22784998
assuming each word is seperated by a single blank

select
  len(your_column) - len(replace(your_column, ' ', ''))
0
 
LVL 37

Accepted Solution

by:
momi_sabag earned 500 total points
ID: 22785002
sorry
it should be
select
  len(your_column) - len(replace(your_column, ' ', '')) + 1
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question