Is there a function in SQL Server to normalize a unicode string? e.g.
UPDATE Orders SET Notes = NormalizeString(Notes, 'FormC')
Unicode Normalization Forms:
- Composition (C):
A
+¨
becomesÄ
- Decomposition (D):
Ä
becomesA
+¨
- Compatible Composition (KC):
A
+¨
+fi
+n
becomesÄ
+f
+i
+n
- Compatible Decomposition (KD):
Ä
+fi
+n
becomesA
+¨
+f
+i
+n
i cannot find any built-in function, so i assume there is none.
Ideally, if there can be only one, then i happen to need Form C today:
Unicode normalization form C, canonical composition. Transforms each decomposed grouping, consisting of a base character plus combining characters, to the canonical precomposed equivalent. For example, A + ¨ becomes Ä.
Sorry, no, there is no such function in any version of SQL Server to date (2012 test builds). Comparisons can be correctly composition-insensitive, but there isn't a function to convert character composition usage to one normal form.
It has been suggested for a future version of the ANSI standard under the syntax
NORMALIZE(string, NFC)
but it's going to be a long time before this makes it to the real world. For now if you want to do normalisation you'll have to do it in a proper programming language with better string-handling capabilities, either by pulling the string out of the database or by writing a CLR stored procedure to do it.I was some problem,
I write a new CRL function in C#, and use like a SQL function.
My C# code (nomalize to NFC or NFD). Also, handle NULL string correctly.:
Use example in SQL query (form any normalization to C):
Installing the normalization function before use (you don't need C# in this case... The binary conatains the use-ready .Net code, see source above):
Compiled with .Net version: 4.6
I don't take any resposinbility the use of the binary code above!
Test example:
try this CLR function
and in SQL
thanks to http://www.dotnetportal.cz/blogy/4/Tomas-Jecha/663/NET-Tip-6-Ciste-odstraneni-diakritiky