CREATE PROCEDURE DBO.ResolveNextToken @AString VARCHAR (100), @Token CHAR (1), @ReturnedValue Varchar (20) output, @ReturnedString Varchar (100) OUTPUT  AS
SET NOCOUNT ON

---Last changed: AV 2009 0211 @returnedvalue altered from 5 to 20 in the lengt

--CREATED AV 20050630
-- The routines purpose is to grab elementes from a string one by one. The elements in the string is separeted with a token e.g a comma. 


  DECLARE @Idx int

  SET @ReturnedValue = ''

  IF @AString = ''
    RETURN  
  
  SET @Idx = 1

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

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

  SET @ReturnedString = SUBSTRING (@AString, @IDX+1, LEN (@AString))
