ASCII Function

The ASCII function returns the decimal representation of the first character in a character string, based on its codepoint in the ASCII character set.
Read syntax diagramSkip visual syntax diagram
ASCII Function

|--ASCII--(--char_expr--)---------------------------------------|

Element Description Restrictions Syntax
char_expr Expression that evaluates to a character data type Must be of type CHAR, LVARCHAR, NCHAR, NVARCHAR, or VARCHAR Identifier

The ASCII function takes a single argument of any character data type. It returns an integer value, based on the first character of the argument, corresponding to the decimal representation of the codepoint of that character within the ASCII character set.

If the argument is NULL, or if the argument is an empty string, the ASCII function returns a NULL value.

The following query returns the ASCII value of uppercase H:
SELECT ASCII("HELLO") FROM systables WHERE tabid = 1;
The following table shows the output of this SELECT statement.
(constant)
72
The following query returns the ASCII value of lowercase h:
SELECT ASCII("hello") FROM systables WHERE tabid = 1;
The following table shows the output of this SELECT statement.
(constant)
104
The following query returns the ASCII output from an empty string argument:
SELECT ASCII("") FROM systables WHERE tabid = 1;
The following table shows the NULL output of this SELECT statement.
(constant)
The following query returns the ASCII output from a NULL argument:
SELECT ASCII(NULL) FROM systables WHERE tabid = 1;
The following table shows the NULL output of this SELECT statement.
(constant)
The ASCII function interprets this argument as a NULL expression, rather than as a value that begins with uppercase N.

For a table of the numeric values of the codepoints in the ASCII character set, see Collating Order for U.S. English Data.