CREATE FUNCTION [dbo].[SplitNumberList] (@splitlist VARCHAR(1000))
RETURNS @table TABLE (value INT)
AS
BEGIN
  SET @splitlist = RTRIM(LTRIM(@splitlist))

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

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

  RETURN 
END