Skip to content
Advertisement

Find the count of words in string

SQL: How to find the count of words in following example?

Subquestions:

  1. How to count spaces?
  2. How to count double/triple/… spaces as one? answer by Gordon Linoff here

  3. How to avoid counting of special characters? Example: 'Please , don't count this comma'

  4. Is it possible without string_split function (because it’s available only since SQL SERVER 2016)?

Summary with the best solutions HERE

Advertisement

Answer

Using string_split (available only since SQL SERVER 2016):

The same idea is used in following answers:

Without using string_split:

The same idea is used in following answers:

As Inline Function:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement