Using UNICODE function or NCHAR function in SQL Server 2012

The T-SQL provides UNICODE function and NCHAR function.

First function get one argument(string expression) as nchar or nvarchar datatype and return int value. This returned value is decimal code for char in UTF-16 encoding. This function get only first char from string(argument of function). It is example for ‘a’ letter.

SELECT UNICODE('a') as [UNICODE(a)]

Result:
ss1
For diacritic chars this function works very well, either.

SELECT UNICODE('ą') as [UNICODE(ą)]

Result:
ss2
For check this values, You may use NCHAR function. This function get one argument as decimal code in UTF-16 of char. It returns nchar(1) value or nvarchar(2) value, it depends on database supplementary characters.

So let check ‘a’ and ‘ą’ letters.

 SELECT NCHAR(97) as [NCHAR(97)] , 
        NCHAR(261) as [NCHAR(261)] ;

Result:
ss3
You may see the same chars, that was be displayed in first and second example.

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.