create function [dbo].[split](@input varchar(max), @split varchar(max)) returns @table table(col varchar(max)) as begin while(charindex(@split,@input)<>0) begin insert @table(col) values (ltrim(rtrim(substring(@input,1,charindex(@split,@input)-1)))) set @input = stuff(@input,1,charindex(@split,@input),'') end insert @table(col) values (ltrim(rtrim(@input))) return end