How to split a string in sql server

 UdayarumilliSplitstringHow to split a string in sql server

We have a requirement to capture the list of key words in the given list of statements. In the below example will see How to split a string in sql server

There is a table called “SearchQueries”. It’s been having a list of queries, now the requirement is to split each and every statement into individual words and needs to be stored in a table “KeyWords”.

 Now the requirement is to split and store keywords from each record as below along with the number of occurrences.

 Example:

KeyWord       Count

Describe           12

Change              2

Data                  10

Capture              1

Etc…….

Script to create table and populate with data:

Create a table to hold the keywords:

Now create a stored procedure to split the given statement into individual words.

The stored procedure splits the statement into individual words. For example if we input a statement “SQL Server 2012” to the stored procedure it splits the statement into words an stored into table “KeyWords”.

i.e

SQL

Server

2012

Using the same logic we will apply the logic to existing table “SearchQueries” and prepare a list of keywords from the table.

Execute the above script to accomplish the task.

Check the table for the list of keywords.

Finally capture the keywords and corresponding counts.

Posted in SQL Development | Tagged , , , , , , , , , , | Leave a comment

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz