Hi, I had a similar solution, that makes use of more or less the same code in a function :
CREATE FUNCTION dbo.fn_clean (@my_string varchar(40))
RETURNS varchar(40)
AS
BEGIN
declare @pos smallint
declare @char char(1)
select @pos = 1
while @pos <= len(@my_string)
begin
if substring(@my_string,@pos,1) like '[A-Z]'
or substring(@my_string,@pos,1) like'[a-z]'
or substring(@my_string,@pos,1) like '[0-9]'
select @pos = @pos + 1
else
begin
select @my_string = stuff (@my_string,@pos,1,'-')
select @pos = @pos + 1
end
end
RETURN (@my_string)
END
Depending on the case, a function might be easier for you to use. Ciao,
Patrick