The best way to achieve this is very simple and efficient :
SELECT 'àéêöhello!' Collate SQL_Latin1_General_CP1253_CI_AI
which outputs ‘aeeohello!’
The string must not be unicode. If you have a nvarchar just cast it to varchar before using the collate.
Here is a function that answers the OP needs :
create function [dbo].[RemoveExtraChars] ( @p_OriginalString varchar(50) )
returns varchar(50) as
begin
declare @i int = 1; -- must start from 1, as SubString is 1-based
declare @OriginalString varchar(100) = @p_OriginalString Collate SQL_Latin1_General_CP1253_CI_AI;
declare @ModifiedString varchar(100) = '';
while @i <= Len(@OriginalString)
begin
if SubString(@OriginalString, @i, 1) like '[a-Z]'
begin
set @ModifiedString = @ModifiedString + SubString(@OriginalString, @i, 1);
end
set @i = @i + 1;
end
return @ModifiedString
end
Then, the command:
select dbo.RemoveExtraChars('aèàç=.32s df')
outputs
aeacsdf