STRING_SPLIT
function in Sql Server 2016
Sql Server
2016 is introduced STRING_SPLIT is one of the new built-in table valued
function.
This
function splits the input string by the specified character separator and
returns output as a table.
SYNTAX:
- STRING_SPLIT ( input_string,
separator)
Where input_string can be type of CHAR,
VARCHAR, NVARCHAR and NCHAR.
Separator
is a single character can be one of the type CHAR(1), VARCHAR(1), NVARCHAR(1)
and NCHAR(1).
Example
1: Simple STRING_SPLIT function example
SELECT * FROM STRING_SPLIT ('www.code-view.com, www.code-sample.com,
www.code-sample.xyz',',')
OUTPUT:-
www.code-view.com
www.code-sample.com
www.code-sample.xyz
Example
2: passing string and separator parameters as
variables
DECLARE @Input_String VARCHAR(MAX) = 'www.code-view.com,www.code-sample.com,www.code-sample.xyz',
@separator CHAR(1) =','
SELECT * FROM STRING_SPLIT(@Input_String, @separator)
OUTPUT:-
www.code-view.com
www.code-sample.com
www.code-sample.xyz
No comments:
Post a comment