Table-valued Functions [rdld].[split_string]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@in_stringvarchar(max)max
@delimitervarchar1
SQL Script
/****** Object:  Function [rdld].[split_string] ******/
-- =============================================
-- Author:     Jeff Spindler
-- Date: 11/22
-- Description: sql server has a function like this, but not in older versions
-- =============================================
CREATE FUNCTION [rdld].[split_string]
(
    @in_string VARCHAR(MAX),
    @delimiter VARCHAR(1)
)
RETURNS @list TABLE(tuple VARCHAR(100))
AS
BEGIN
        WHILE LEN(@in_string) > 0
        BEGIN
            INSERT INTO @list(tuple)
            SELECT left(@in_string, charindex(@delimiter, @in_string+',') -1) as tuple
    
            SET @in_string = stuff(@in_string, 1, charindex(@delimiter, @in_string + @delimiter), '')
        end
    RETURN
END
GO
Uses
Used By