declare @a varchar(8),@b varchar(8)
set @a='11122334'
while @a<>''
begin
select @b=isnull(@b,'')+case when len(@b)>0 and right(@b,1)=substring(@a,1,1) then '' else substring(@a,1,1) end,@a=right(@a,len(@a)-1)
print @b+' '+@a
end
如果是要不管相邻不相邻的都去掉的话:
declare @a varchar(8),@b varchar(8)
set @a='11223314'
while @a<>''
begin
select @b=isnull(@b,'')+case when @b like '%'+substring(@a,1,1)+'%' then '' else substring(@a,1,1) end,@a=right(@a,len(@a)-1)
print @b+' '+@a
end