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.