String Functions – Count Words
In SQL Server, there's no built-in function
that will return the number of words a given string contains.
DECLARE @String VARCHAR(4000)
SET @String = 'Health Insurance is an
insurance against expenses incurred through illness of the insured.'
SELECT LEN(@String) - LEN(REPLACE(@String, ' ', '')) + 1
This query will return a value of 13, which is
the number of words in the given string.
No comments:
Post a Comment