Gerrit Mantel
Programs SQL_TABLE_VALUED_FUNCTION - fun_nsplit_notrim

Main program

Namefun_nsplit_notrim
Type_descSQL_TABLE_VALUED_FUNCTION
CommentSQLServer User-Defined Function

PURPOSE
Split delimited n-string into record values.

This UDF is based upon fn_Split described in https://odetocode.com/articles/365.aspx

The output values are not left and right trimmed.

EXAMPLES
1)
SELECT [position], [value] FROM dbo.fun_nsplit(N'foo,bar,widget', N',')
1 foo
2 bar
3 widget

2)
SELECT [position], [value] FROM dbo.fun_nsplit(N'foo,bar,,widget', N',')
position value
1 foo
2 bar
3
4 widget

3)
SELECT [position], [value] FROM dbo.fun_nsplit(N'foo,bar,widget,', N',')
position value
1 foo
2 bar
3 widget
4

HISTORY
2005-03-21 - Created function
2018-01-22 - Limited @delimiter to NVARCHAR(1)
- Changed table variable @Strings to @strings
2024-02-09 - Changed history table
2024-02-14 - Extended @delimiter to VARCHAR(10)
Fixed bug: Last empty value was not detected
2024-04-09 - Correct NULL delimiter

TAGS
<program>
<description>Split delimited n-string into record values</description>
<generic>1</generic>
<author>Gerrit Mantel</author>
<created>2005-03-21</created>
<lastmodified>2024-04-09</lastmodified>
</program>
DescriptionSplit delimited n-string into record values
Minversion
Generic1
AuthorGerrit Mantel
Created2005-03-21 00:00:00
Lastmodified2024-04-09 00:00:00
Xp_cmdshell0
Ole_automation0
Subprogram_cnt0
Sourcecode