Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

String Character Count

By Benson Sibanda,


A while ago I once attended an interview where I was asked to write a short script that counts each letter of a given string and provide a grouping for each. This Script counts the number of times each letter appears in a string. It gives each letter and the number of occurrences. I have provided two methods. The first is a CTE based method and the second is a while loop. I havent tested this with a large data set but for a string with few characters both methods will be good performance wise.

Total article views: 1523 | Views in the last 30 days: 7
 
Related Articles
FORUM

find whether a upper case letter is there in a given string

find whether a upper case letter is there in a given string

FORUM

Identify letter vs. number

Parsing letters from numbers in a character entry

FORUM

Sql Server 2005 Sorting when having both english letter 'e' and french letter 'é'

eswaran_r (Sql Server 2005 Sorting when having both english letter 'e' and french letter 'é')

SCRIPT

Drive Letter Finder

Find the first available drive letter (working backwards from z)

BLOG

SQL Server Connection Strings

The purpose of this short post is to demonstrate a simple method of generating an accurate SQL Serve...

 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones