SQL Split String -Funktion

CREATE FUNCTION [dbo].[Func_SplitString] 
( @Values VARCHAR(MAX)
, @splitStr VARCHAR(50)
)

RETURNS @Result_Table TABLE
       (
	     [value] nvarchar(MAX) NULL
       )
BEGIN
    DECLARE @TempStr nvarchar(MAX)
    WHILE (CHARINDEX(@splitStr,@Values)>0)
    BEGIN
        SET @TempStr=SUBSTRING(@Values,1,CHARINDEX(@splitStr,@Values)-1)
        INSERT INTO @Result_Table (value) VALUES (ltrim(rtrim(isnull(@TempStr, ''))))
        SET @Values = REPLACE(@Values,@TempStr+@splitStr,'')
    END/*End While*/
	
    IF(LEN(RTRIM(LTRIM(@Values)))>0 AND CHARINDEX(@splitStr,RTRIM(LTRIM(@Values)))=0) 
    BEGIN
        SET @TempStr=@Values 
        INSERT INTO @Result_Table (value) VALUES (ltrim(rtrim(isnull(@TempStr, ''))))
    End /*End IF*/
   RETURN 
END
BlackSwan