Using ASCII function or CHAR function in SQL Server 2012

The T-SQL provides ASCII function and CHAR function.

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

SELECT ASCII('a') as [ASCII(a)] ;

Result:

qq1

For diacritic chars this function works very well, either.

SELECT ASCII('ą') as [ASCII(ą)] ;

Result:

For check this values, You may use CHAR function. This function get one argument as decimal code in ASCII of char( the integer from 0 through 255 ). It returns char(1) value.

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

 SELECT CHAR(97) as [CHAR(97)] , 
        CHAR(185) as [CHAR(185)] ;

Result:

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