SQL STRING_SPLIT Function

The SQL STRING_SPLIT function is used to split the string expressions using a specified separator, and its syntax is

STRING_SPLIT (String_Expression, Separator)

The list of arguments available for the method is:

  • String_Expression: Please specify a valid String Expression
  • Separator: This SQL Server function will use this separator to split the string_expression.

SQL String_Split Function Example

The following String query will split the declared string using empty spaces in between the words.

DECLARE @Expression varchar(50)
SET @Expression = 'Learn SQL Server at Tutorial Gateway For Free!' 

SELECT VALUE FROM STRING_SPLIT (@Expression, ' ')
Split using Empty Space 1

In this example, we are going to use the String_Split to split the English Product Name column using space separator.

USE [AdventureWorksDW2017]
GO
SELECT  EnglishProductName, 
        VALUE 
FROM [DimProduct]
CROSS APPLY
	  STRING_SPLIT([EnglishProductName], ' ')
SQL STRING_SPLIT Example 2

In this example, we are going to use SQL Server String_Split function to break the English Description column using a space separator.

USE [AdventureWorksDW2017]
GO
SELECT  EnglishDescription, 
        VALUE 
FROM [DimProduct]
CROSS APPLY
	  STRING_SPLIT([EnglishDescription], ' ')
SQL STRING_SPLIT Function 3

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.