| Comment | SQLServer 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> |