Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
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: 1634 | Views in the last 30 days: 2
 
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

ARTICLE

Splitting Strings in SQL Server 2016

Comparison of the new methods of splitting strings in SQL Server 2016 to the tried and true methods

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)

 
Contribute