declare @MyString varchar(500)
set MyString = '1,2.3#45.#,.6'
select dbo.RemoveChars(MyString, '#,.')
create function [dbo].[RemoveChars] (
@InputString varchar(MAX)
,@CharsToRemove varchar(500)
)
returns varchar(MAX)
as
begin
declare @len int
,@Counter int
,@OneChar char(1)
set @Counter = 1
set @len = LEN(@CharsToRemove);
while (1 = 1)
begin
set @OneChar = SUBSTRING(@CharsToRemove, @Counter, 1)
set @InputString = REPLACE(@InputString, @OneChar, '')
set @Counter = @Counter + 1
if (
@Counter > @len
or @Counter > 20
)
break;
end
return @InputString
end