create function elimination(@str1 varchar(20),@str2 varchar(10)) returns varchar(20)
as
begin
declare @str varchar(20),@i int,@j int,@k int
set @str=@str1
set @i=1
set @k=0
while(@i<=len(@str1))
begin
set @j=1
while(@j<=len(@str2))
begin
if substring(@str1,@i,1)=substring(@str2,@j,1)
goto loop
else
set @j=@j+1
end
if @j=len(@str2)+1
begin
set @k=@k+1
set @str=stuff(@str,@k,1,substring(@str1,@i,1))
end
loop:set @i=@i+1
end
set @str=substring(@str,1,@k)
return @str
end
select dbo.elimination('abcdefg12345','bd2')