create or alter function dbo.SplitCsv ( @IdsCsv varchar(max) ) returns @result table ( Id int not null ) as begin declare @IdsXml xml = '<x v="' + replace(@IdsCsv, ',','"/><x v="') + '"/>' insert into @result(Id) select n = T.c.value('@v', 'int') from @IdsXml.nodes('x') T(c) return end