CREATE FUNCTION dbo.fn_SplitString
(
    @List NVARCHAR(MAX),
    @Delimiter CHAR(1)
)
RETURNS @Result TABLE (Value NVARCHAR(500))
AS
BEGIN
    DECLARE @Pos INT, @NextPos INT, @Value NVARCHAR(500)

    SET @List = LTRIM(RTRIM(@List))
    SET @Pos = 1

    WHILE @Pos <= LEN(@List)
    BEGIN
        SET @NextPos = CHARINDEX(@Delimiter, @List, @Pos)
        IF @NextPos = 0 
            SET @NextPos = LEN(@List) + 1

        SET @Value = LTRIM(RTRIM(SUBSTRING(@List, @Pos, @NextPos - @Pos)))

        IF @Value <> ''
            INSERT INTO @Result (Value) VALUES (@Value)

        SET @Pos = @NextPos + 1
    END

    RETURN
END