Gerrit Mantel
Programs SQL_TABLE_VALUED_FUNCTION - fun_split_notrim

Main program

Namefun_split_notrim
Type_descSQL_TABLE_VALUED_FUNCTION
CommentSQLServer User-Defined Function

PURPOSE
Split delimited string into record values (not trimmed).

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_split_notrim('foo,bar,widget', ',')
1 foo
2 bar
3 widget

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

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

HISTORY
2024-02-13 - Created function
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 string into record values (not trimmed)</description>
<generic>1</generic>
<author>Gerrit Mantel</author>
<created>2024-02-13</created>
<lastmodified>2024-04-09</lastmodified>
</program>
DescriptionSplit delimited string into record values (not trimmed)
Minversion
Generic1
AuthorGerrit Mantel
Created2024-02-13 00:00:00
Lastmodified2024-04-09 00:00:00
Xp_cmdshell0
Ole_automation0
Subprogram_cnt0
Sourcecode