CREATE FUNCTION [dbo].[SplitStringForDataRepeaterSplitText]  
(  
    @string NVARCHAR(MAX) , @MXLen int
)  
RETURNS @output TABLE(
	splitdata NVARCHAR(MAX), 
	col1 NVARCHAR(50), 
	col2 NVARCHAR(50), 
	col3 NVARCHAR(50)
)  
BEGIN  
    DECLARE @start INT, @end INT  

	DECLARE @ItemCode NVARCHAR(50) 
	DECLARE @COL1 NVARCHAR(50) 
	DECLARE @COL2 NVARCHAR(50) 
	DECLARE @COL3 NVARCHAR(50) 

    SELECT @start = 1, @end = CHARINDEX('##', @string)  
    WHILE @start < LEN(@string) + 1 BEGIN  
        IF @end = 0   
            SET @end = LEN(@string) + 2 

	  	SET @ItemCode = SUBSTRING( SUBSTRING(@string, @start, @end - @start), 1, CHARINDEX(' * ', SUBSTRING(@string, @start, @end - @start)) - 1 )

		SELECT @COL1 = Col1, @COL2 = Col2, @COL3 = Col3 from PMX_SplitTextIntoThreeColumns ( REPLACE(SUBSTRING(@string, @start, @end - @start), @ItemCode + ' * ', '') , @MXLen)

        INSERT INTO @output (splitdata, COL1, COL2, COL3) 
		VALUES(	@ItemCode, @COL1, @COL2, @COL3)  

        SET @start = @end + 2  
        SET @end = CHARINDEX('##', @string, @start) 
    END  
    RETURN  
END 