Please explain for me why is the below string's length is 9 instead of 8?
DECLARE @nstring NVARCHAR(100)
SET @nstring =N'Không có'
Print len(@nstring) -- 9
SET @nstring =N'Không co'
Print len(@nstring) -- 8
Please explain for me why is the below string's length is 9 instead of 8?
DECLARE @nstring NVARCHAR(100)
SET @nstring =N'Không có'
Print len(@nstring) -- 9
SET @nstring =N'Không co'
Print len(@nstring) -- 8
For some characters, there are several ways they can be encoded as Unicode.
In this case, an "ó" can be either U+00F3 (one 16-bit value) or U+006F U+0301 (two 16-bit values). These forms are canonically equivalent.
If you feel like reading a bit more, Using Unicode Normalization to Represent Strings by Microsoft.
Unfortunately, there is no way in T-SQL to convert a string from one form into another. See also questions like Normalize unicode string in SQL Server?
But the good news is since they're canonically equivalent, they compare the same in T-SQL (you can write N'Không có'=N'Không có'
and the result is true) so it's not that big a problem as you may think at first.