Technical Article

STRING_SPLIT with Index as Table-Valued Function

,

This simple table-valued function, when combined with an APPLY operator, allows you to identify nth position strings within a string that has separators.

CREATE FUNCTION [capinv].[tvfn_String_Split_with_Index]
( 
@String varchar(max)
,@Separator varchar(10)
)
RETURNS TABLE 
AS
RETURN 
(
SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 1)) AS [Index], value AS [Character]
FROM STRING_SPLIT(@String, @Separator)
)
GO

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating