cindi cindi - 7 months ago 21
SQL Question

How to count instances of character in SQL Column

I have an sql column that is a string of 100 'Y' or 'N' characters. For example:


YYNYNYYNNNYYNY...


What is the easiest way to get the count of all 'Y' symbols in each row.

Answer

if ms sql

SELECT LEN(REPLACE(myColumn, 'N', '')) FROM ...
Comments