August 16, 2010

Count the Number of Occurrence of Characters in a String – SQL Server Challenge




BeyondRelational.com is back with another challenge this week. This challenge is all about counting the number of occurrence of characters in a string using a SET based query. The task is to list all the characters and count of that character within the given string

Challenge URL: Count the Number of Occurrence of Characters in a String

I had written a similar article sometime back which can give you some hints on how to solve the challenge. Check the article here Count Occurrences of Characters in a String – SQL Server

DECLARE @longWord varchar(28)='AntiDisEstablishmentArianism'

SELECT CountCharacters =
DATALENGTH(@longWord)
- DATALENGTH (REPLACE(REPLACE(LOWER(@longWord),'a',''),'i',''))

Remember the code shown above is just a hint on counting character occurrence and not the solution. Read the challenge and its rules carefully over here.


Did you like this post?
kick it on DotNetKicks.com
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

 
  Feedback:

comments

0 Responses to "Count the Number of Occurrence of Characters in a String – SQL Server Challenge"
 

Copyright © 2009-2014 All Rights Reserved for SQLServerCurry.com by Suprotim Agarwal | Terms and Conditions