CREATE FUNCTION dbo.GetNextToken (@AString VARCHAR (100), @Token CHAR (1) )  
RETURNS Varchar (5)
BEGIN 

DECLARE @Return Varchar (5)
DECLARE @Idx int

SET @Return = ''

  IF @AString <> ''
  BEGIN
  
    SET @Idx = 1

    WHILE @idx <= LEN(@AString) AND (SUBSTRING(@AString,@Idx,1) <> @Token) 
      SET @IDX = @IDX +1

    SET @Return = SUBSTRING (@AString, 1, @Idx -1 )

  END

Return @Return

END

