Count of words in column

Input Data:


Output Data:



DECLARE @WordCount TABLE

(

       [Word List] varchar(100)

)

INSERT INTO @WordCount

VALUES

('Adam Michelle Larry'),('Pisa London Moscow Delhi'),

('Maths Physics'),('England'),('a b c d e f g h') 

 

SELECT * FROM @WordCount

SELECT [Word List],LEN([Word List]) - LEN(REPLACE([Word List], ' ', '')) + 1 AS [Count] FROM @WordCount



Comments

Post a Comment

Hi User,
Thanks for visiting My Blog and please provide your valuable feedback and subscribe for more updates. Please don't post any spam content or comments.
Thank You

Popular Posts

Failed to execute the package or element. Build errors were encountered

Restore of database 'DataBase_Name' failed. (Microsoft.SqlServer.Management.RelationalEngineTasks)

Get List of logins on SQL Server instance