USE [DriveMaintenance]
GO

DECLARE @functionName NVARCHAR(128) = N'SplitIn';

IF EXISTS (
    SELECT 1 
    FROM sys.objects AS o
    WHERE o.name = @functionName
      AND o.type IN ('FN', 'TF')
      AND o.is_ms_shipped = 0
)
BEGIN
    DROP FUNCTION [dbo].[SplitIn]
END

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[SplitIn]
(
    @c VARCHAR(2000),
    @split VARCHAR(2)
)
RETURNS @t TABLE
(
    col VARCHAR(20)
)
AS
BEGIN
    WHILE (CHARINDEX(@split, @c) <> 0)
BEGIN
        INSERT @t
        (
            col
        )
        VALUES
        (SUBSTRING(@c, 1, CHARINDEX(@split, @c) - 1));
        SET @c = STUFF(@c, 1, CHARINDEX(@split, @c), '');
END;
    INSERT @t
    (
        col
    )
    VALUES
    (@c );
    RETURN;
END;
GO