Skip to content
Related Articles

Related Articles

ASCII() Function in SQL Server
  • Last Updated : 07 Oct, 2020

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

Syntax :

ASCII(character_expression)

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.

SELECT ASCII('A') AS A, ASCII('a') AS a,
ASCII('Z') AS Z, ASCII('z') AS z;

Output :



AaZz
659790122



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@
49355764



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

SELECT ASCII('GeeksForGeeks');

Output :

71



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

PlayerIdPlayerNameCity
45Rohit SharmaMumbai
18Virat KohliBangalore
7MS DhoniChennai
33Hardik PandyaMumbai
42Sikhar DhawanDelhi
SELECT PlayerName, ASCII(PlayerName) AS AsciiCodeOfFirstChar
FROM Player_Details;

Output :

PlayerNameAsciiCodeOfFirstChar
Rohit Sharma82
Virat Kohli86
MS Dhoni77
Hardik Pandya72
Sikhar Dhawan83
My Personal Notes arrow_drop_up
Recommended Articles
Page :