Collation SQL can not help in this case. It will define at most that accent and case (uppercase / lowercase) should be ignored in searches.
In order to do the conversion and in fact to keep everything in uppercase, without an accent, you need to convert the text before it persists, using some specific function.
MS SQL Server has no native function to remove accent. You would have to create this function yourself in SQL, or create this function in the application layer if you have one (in C # or Java, for example).
Algorithm
One of the ways to do this is to use two arrays to make a from-to , from there you go through the word, character, search for the position of the original character in the first array, character in the second array, in this same position.
Having only the accented characters and their substitutes in the arrays, if a character is not found, just return it yourself.
In addition to character substitutions accented by non-accented characters, you should also convert all to upper case (for this the languages already include native function, including SQL Server).
Ready-made language functions
Eventually the language you use already has some functions ready to help with some of the work.
For example, C # has String.Normalize
that already helps a lot. See this example : p>
static string RemoveDiacritics(string text)
{
var normalizedString = text.Normalize(NormalizationForm.FormD);
var stringBuilder = new StringBuilder();
foreach (var c in normalizedString)
{
var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
if (unicodeCategory != UnicodeCategory.NonSpacingMark)
{
stringBuilder.Append(c);
}
}
return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
}
The code above first separates the letters of your accents or cedilla using String.Normalize , and then traverses the result by removing the accent characters that were separated from the letters, leaving only the letters
To the result of this function above you still have to apply string.UpperCase()
. More or less like this:
static void Main(string[] args)
{
var textoOriginal = "É é ç";
var textoConvertido = RemoveDiacritics(textoOriginal).ToUpper();
Console.WriteLine(textoConvertido);
}
The output of the above code is E E C
.