CREATE FUNCTION [dbo].[fnSplitString] 
( 
    @string varchar(1000) , 
    @delimiter CHAR(1) 
) 
RETURNS @output TABLE(splitdata varchar(1000) 
) 
BEGIN 
    DECLARE @start INT, @end INT 
    SELECT @start = 1, @end = CHARINDEX(@delimiter, @string) 
    WHILE @start < LEN(@string) + 1 
    BEGIN 
		IF @end = 0  
		  SET @end = LEN(@string) + 1
	   
		INSERT INTO @output (splitdata)  
		VALUES(Ltrim(RTrim(SUBSTRING(@string, @start, @end - @start)))) 
		SET @start = @end + 1 
		SET @end = CHARINDEX(@delimiter, @string, @start)
    END 
    RETURN 
END


