SQL STRING_SPLIT Function

The SQL STRING_SPLIT function is used to split the string expressions using a specified separator. The syntax of the SQL Server STRING_SPLIT function is

STRING_SPLIT (String_Expression, Separator)

The list of arguments available for STRING_SPLIT 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 1

The following String Function 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, ' ')
SQL STRING_SPLIT Function 1

SQL String Split Function Example 2

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

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

SQL Server STRING_SPLIT Example 3

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

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