Split
Splits a string into one or more substrings (Simple Version)
- Free Function
- SQL Server Compatibility: 2008, 2012, 2014, 2016, 2017
SELECT SQLHTTP.net.Split ( @Text, @Delimiter, @Index )
Name | Type | Description |
---|---|---|
@Text | nvarchar(MAX) |
String expression containing substrings and delimiters. |
@Delimiter | nvarchar(4000) |
String of characters used to identify substring limits. |
@Index | bigint | Integer value specifying the location of a substring. |
nvarchar(MAX)
Simple split by a space character:
1 2 3 4 5 6 7 8 9 10 11 |
DECLARE @Text nvarchar(MAX) DECLARE @Delimiter nvarchar(4000) DECLARE @Index bigint SET @Text = 'The quick brown fox jumps over the lazy dog' SET @Delimiter = ' ' --one space character SET @Index = 4 SELECT SQLHTTP.net.Split(@Text, @Delimiter, @Index) |
1 2 3 4 5 |
----- fox |
Simple split by a two-character delimiter:
1 2 3 4 5 6 7 8 9 10 11 |
DECLARE @Text nvarchar(MAX) DECLARE @Delimiter nvarchar(4000) DECLARE @Index bigint SET @Text = 'The quick brown fox jumps over the lazy dog' SET @Delimiter = 'e ' --two character delimiter SET @Index = 3 SELECT SQLHTTP.net.Split(@Text, @Delimiter, @Index) |
1 2 3 4 |
---------- lazy dog |