Word Count in SQL Server – String_Split Usage

STRING_SPLIT is a table-valued function that splits the words from the input text and returns into rows. This function has been introduced in SQL Server 2016.

String_split will help in many ways.

1) You can get the word count from the given text.
2) You can pass the string values to a query.

Word Count in SQL
SELECT COUNT(value)
FROM
    STRING_SPLIT(‘This is just a text taken from the most popular book’, ‘ ‘)

WordCount_SQLServer_string_split

String_Split in Queries to provide multiple values in where clause.

DECLARE @EmpIDs NVARCHAR(100) = ‘7369,7499,7521’
SELECT Ename
FROM   Emp
WHERE  Empno IN (SELECT value FROM STRING_SPLIT(@EmpIDs, ‘,’))

string_split_1

 
 
If you are looking for a word-count program using HiveQL, then click here.
If you are looking for a word-count program using Pig, then click here.

6 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s