Thursday, April 12, 2012

SQL - Count Character Occurrence in a String


Want to count the number of times a specific character appears within a string? The line below will count the number of times the letter 'a' appears within the string value returned from the column 'description'.  I display the column for description and a column for the count side by side.

select description, len(description)-len(replace(description,'a','')) as 'count' from table_items

No comments:

Post a Comment