Listing 1: SplitParameterWithCommas 

--##SUMMARY   Return a table with one row for each of the values
--##SUMMARY   supplied in the comma separated list (NB int values only)
--##DETAILS   Useful for inserting into temporary tables or for doing
--##DETAILS   stored results
--##DETAILS   E.g. select * from SplitParameterWithCommas('1,3,5,3,7,1,4,6,7,3')

CREATE FUNCTION SplitParameterWithCommas (@paramList varchar(3000))

RETURNS @params TABLE
   (
    ID     int
   )
AS
BEGIN

declare @start_char int, @paramVal varchar(100), @charTemp char(1)
select @start_char = 1
select @paramVal = '' 
while (@start_char <= len(@paramList))
begin
	select @charTemp = SUBSTRING ( @paramList , @start_char , 1 )
	if (@charTemp = ',') 
	begin
		insert into @params values (@paramVal)
		select @paramVal = '' 
	end
	else
	begin
		select @paramVal = @paramVal + @charTemp
	end	
	select @start_char = @start_char + 1
end

insert into @params values (@paramVal)

RETURN

END