Technical Article

Count Number of Words and Characters

,

The given is self explanatory. You can create function to use it in your queries.

The first section finds the specific character in the string.

The second section counts the words in the string.

-- Number of specific Characters
Declare @aa varchar(100)
Set @aa = 'SQL Server 2005000'
Select Len(@aa) - Len(Replace(@aa, '0', ''))

-- Number of Words 
DECLARE @String VARCHAR(4000)
SELECT @String = 'SQL Server 2005 Atif Sheikh A'

while CharIndex(' ',@String) > 1
begin    
    Set @String = REPLACE(@String, ' ', ' ')
end
Select @String
SELECT LEN(@String) - LEN(REPLACE(@String, ' ', '')) + 1

Rate

1.5 (8)

You rated this post out of 5. Change rating

Share

Share

Rate

1.5 (8)

You rated this post out of 5. Change rating