SQL Eval Function String_Split
String_Split
returns a string array that contains the substrings in the source
string that are delimited by elements of a specified delimStr
string.
String_Split ( @source NVARCHAR (MAX), @delimStr NVARCHAR (MAX) ) RETURNS TABLE ([Match] NVARCHAR (MAX) NULL)
Parameters
- source: The source string.
- delimStr: A string that is converted to character array that delimits the substrings in the
source
string, an empty array that contains no delimiters, ornull
.
Returns
- A string that is equivalent to the
source
string except that all instances ofoldValue
are replaced withnewValue
. - If
oldValue
is not found in thesource
string, the method returns thesource
string without any changes.
Example
SELECT * FROM String_Split(',ONE,,TWO,,,THREE,,', ',') SELECT * FROM String_Split('1,2,3,4;5;6;:7:8:9', ',;:')
String_Split4k
It is equivalent to String_Split
except no NVARCHAR(MAX) parameters; it can be used when input data will never be over 4000 characters as this function offers better performance.
String_Split4k ( @source NVARCHAR (4000), @delimStr NVARCHAR (4000) ) RETURNS TABLE ([Match] NVARCHAR (4000) NULL)
Example
SELECT * FROM String_Split4k(',ONE,,TWO,,,THREE,,', ',') SELECT * FROM String_Split4k('1,2,3,4;5;6;:7:8:9', ',;:')