ASCII (Transact-SQL)

THIS TOPIC APPLIES TO: yesSQL Server (starting with 2008)yesAzure SQL DatabaseyesAzure SQL Data Warehouse yesParallel Data Warehouse

Returns the ASCII code value of the leftmost character of a character expression.

Topic link icon Transact-SQL Syntax Conventions

Syntax

ASCII ( character_expression )  

Arguments

character_expression
Is an expression of the type char or varchar.

Return Types

int

Remarks

ASCII is an abbreviation for American Standard Code for Information Interchange. It is a character encoding standard used by computers. For a list of ASCII characters, see the Printable characters section of ASCII.

Examples

The following example assumes an ASCII character set and returns the ASCII value for 6 characters.

SELECT ASCII('A') AS A, ASCII('B') AS B,   
ASCII('a') AS a, ASCII('b') AS b,  
ASCII(1) AS [1], ASCII(2) AS [2];  

Here is the result set.

A           B           a           b           1           2  
----------- ----------- ----------- ----------- ----------- -----------  
65          66          97          98          49          50  

See Also

String Functions (Transact-SQL)