-1

For example, I have 100001,100002, stored in a NVARCHAR column.

I want to count the number of occurrences of , in this column.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Alfred Lau
  • 21
  • 2
  • `select len(col) - len(replace(col, ',', ''))` – juergen d May 23 '16 at 16:23
  • @juergen d: Too bad; your comment would have been my answer :-) – Thorsten Kettner May 23 '16 at 16:24
  • 1
    @ThorstenKettner Just as well you didn't answer as there are [plenty](http://stackoverflow.com/questions/9789225/number-of-times-a-particular-character-appears-in-a-string) [of](http://stackoverflow.com/questions/287373/how-can-you-find-the-number-of-occurrences-of-a-particular-character-in-a-string) [dupe](http://stackoverflow.com/questions/738282/how-do-you-count-the-number-of-occurrences-of-a-certain-substring-in-a-sql-varch) targets! – DavidG May 23 '16 at 16:31

1 Answers1

0

select len('100001,100002,') - len(replace('100001,100002,',',',''))

returns 2

John Cappelletti
  • 79,615
  • 7
  • 44
  • 66