How to count instances of character in SQL Column

前端 未结 16 1748
你的背包
你的背包 2020-11-27 12:57

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

YYNYNYYNNNYYNY...

What is the easiest way

16条回答
  •  心在旅途
    2020-11-27 13:16

    This will return number of occurance of N

    select ColumnName, LEN(ColumnName)- LEN(REPLACE(ColumnName, 'N', '')) from Table

提交回复
热议问题