CREATE FUNCTION [DBO].[SplitList] (@splitlist VARCHAR(1000)) 
RETURNS @table TABLE (value VARCHAR(100)) AS
BEGIN

  /*
    Created by Kent Johansen January 2009
    Notes:
    Changes:
  */

  SET @splitlist = RTRIM(LTRIM(@splitlist))

  DECLARE @nextcharindex INT
  SET @nextcharindex = CHARINDEX(',', @splitlist, 1) 

  WHILE 1 < @nextcharindex
  BEGIN
    INSERT @table SELECT SUBSTRING(@splitlist, 1, @nextcharindex-1)
    SET @splitlist = RTRIM(LTRIM(SUBSTRING(@splitlist, @nextcharindex+1, len(@splitlist))))
    SET @nextcharindex = CHARINDEX(',', @splitlist, 1) 
  END
  INSERT @table SELECT SUBSTRING(@splitlist, 1, len(@splitlist))

  RETURN 
END