ASCII() Function in SQL Server

The ASCII() function returns the ASCII value of the leftmost character of a character expression.

Syntax :


Parameter :
This method accepts a single-parameter as mentioned above and described below :
character_expression :
It can be a literal character, an expression of a string, or a column. If more than one character is entered, it will only return the value for the leftmost character.
Returns :
It returns the ASCII code value of its leftmost character.

Example-1 :
When the arguments hold the single uppercase and lowercase letter.

ASCII('Z') AS Z, ASCII('z') AS z;

Output :

A a Z z
65 97 90 122

Example-2 :
When the arguments hold the single number and special character.

SELECT ASCII('1') AS [1], ASCII('#') AS #,
ASCII(9) AS [9], ASCII('@') AS [@]; 

Output :

1 # 9 @
49 35 57 64

Example-3 :
When the arguments hold the expression of a string.

SELECT ASCII('GeeksForGeeks');

Output :


Example-4 :
Using ASCII() function with table columns.
Table – Player_Details

PlayerId PlayerName City
45 Rohit Sharma Mumbai
18 Virat Kohli Bangalore
7 MS Dhoni Chennai
33 Hardik Pandya Mumbai
42 Sikhar Dhawan Delhi
SELECT PlayerName, ASCII(PlayerName) AS AsciiCodeOfFirstChar
FROM Player_Details;

Output :

PlayerName AsciiCodeOfFirstChar
Rohit Sharma 82
Virat Kohli 86
MS Dhoni 77
Hardik Pandya 72
Sikhar Dhawan 83
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.