Skip to content

Instantly share code, notes, and snippets.

@acanalesg
acanalesg / itemAtIndexInASplitString
Created January 29, 2022 11:15 — forked from klimaye/itemAtIndexInASplitString
sql scaler function to return an item at a specific index in a split string. Was useful to me in a select clause parsing a value like Age_0_14
CREATE FUNCTION dbo.itemAtIndexInASplitString( @stringToSplit VARCHAR(MAX), @delimiter VARCHAR(5), @indexToReturn int)
RETURNS
varchar(max)
AS
BEGIN
DECLARE @returnList TABLE ([ID] int, [Name] [nvarchar] (500))
DECLARE @name NVARCHAR(255)
DECLARE @pos INT
DECLARE @index INT
DECLARE @return_value varchar(max)