August 16, 2010

Count the Number of Occurrence of Characters in a String – SQL Server Challenge 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 (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.

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

No comments: