Replace only match beginning of line
I am trying to write a function to replace Romanian diacritics ( ÄĆĆČČ
) with their Latin letter equivalents ( AAIST
respectively).
The SQL Server replace
feature deals with Ä
, Ć
and Ć
just fine.
We seem to have a strange problem with Č
and Č
: they are only replaced if they are at the beginning of the line.
For example :
select replace(N'Č', N'Č', N'-')
-- '-' # OK
select replace(N'ČA', N'Č', N'-')
-- '-A' # OK
select replace(N'AČ', N'Č', N'-')
-- 'AČ' # WHAT??
select replace(N'ČAČ', N'Č', N'-')
-- '-AČ' # WHAT??
I was able to reproduce this behavior on both SQL Sever 2008 R2 and SQL Server 2012.
Is there an explanation for these seemingly strange results? Or could it just be a mistake?
My default database collation is SQL_Latin1_General_CP1_CI_AS
.
source to share