Tricky case: the original pattern (?<![a-zA-Z])N' strips any N'
where N isn't preceded by a letter. That's correct for a leading
unicode prefix (... = N'text' ...) but WRONG for trailing N inside
a string ending with a digit, like N'BD-3N':
1st match: prefix N' → ' → 'BD-3N'
2nd match: string N' → ' → 'BD-3' (bug: stripped the trailing N!)
That bug silently corrupted ISO codes in v5.25 Metadata_Sync and
caused spCreateStateProvince to hit UQ_StateProvince_ISO3166_2.
Fix: only strip N' in contexts where a string literal starts — i.e.
after a non-quote boundary character (whitespace, punctuation, paren,
operator, comma, equals, start of line). This leaves N' inside a
string alone.
Remove T-SQL's N' unicode-string prefix.
Tricky case: the original pattern
(?<![a-zA-Z])N'strips any N' where N isn't preceded by a letter. That's correct for a leading unicode prefix (... = N'text' ...) but WRONG for trailing N inside a string ending with a digit, likeN'BD-3N': 1st match: prefix N' → ' →'BD-3N'2nd match: string N' → ' →'BD-3'(bug: stripped the trailing N!) That bug silently corrupted ISO codes in v5.25 Metadata_Sync and caused spCreateStateProvince to hit UQ_StateProvince_ISO3166_2.Fix: only strip N' in contexts where a string literal starts — i.e. after a non-quote boundary character (whitespace, punctuation, paren, operator, comma, equals, start of line). This leaves N' inside a string alone.