Sunday, February 19, 2012

Counting the occurance of an alphabet in a String

Hi,
I want to count the occurance of an alphabet in a String For example
If the string is "APPLE"
If I want to count the occurance of the letter 'P' in "Apple" the result should be 2
How do I do this.
ThanksThere might be a more efficient way, but what I have done is this:

SELECT
LEN(myColumn) - LEN(REPLACE(myColumn,'P','')) AS NumberOfOccurrences
FROM
myTable

Terri

No comments:

Post a Comment