IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[fn_split_int]') AND type = 'TF')
DROP FUNCTION [dbo].[fn_split_int]
GO
create function [dbo].[fn_split_int](
 @str varchar (max) 
)      
RETURNS @vt table (value int)      
BEGIN      
  declare @i int,@curInd int,@strlen int,@tmps varchar(100) ,@srcs varchar(max)
set @srcs = @str 
select @curInd=1,@strlen=LEN(@srcs) 
while (@curInd<=@strlen) 
begin 
select @i=charindex(',',@srcs,@curInd) 
if (@i>0) 
begin 
select @tmps=SUBSTRING(@srcs,@curInd,@i-@curInd) 
set @curInd=@i+1 
end else if (@curInd<=@strlen) 
begin 
select @tmps=SUBSTRING(@srcs,@curInd,@strlen-@curInd+1) 
set @curInd=@strlen+1 
end 
if (@tmps>'') insert into @vt(value) values(convert(int,@tmps)) 
end
  RETURN      
END