SQL Server ASCII() Function
The ASCII()
function in SQL Server gets the ASCII (American Standard Code for Information Interchange) value of a character. ASCII is a numerical representation of characters, where each character has a unique numerical code.
ASCII(): Definition and Usage
This function is useful when you need to work with the underlying numerical representation of characters, perhaps for character comparisons, data validation, or specialized text processing.
Syntax
Syntax
ASCII(character)
Parameter Values
Parameter | Description |
---|---|
character |
The character for which you want the ASCII value. Only the first character of the string is considered. This is required. |
Example
Getting the ASCII Value of a Character
This example retrieves the ASCII value of the first character in the 'CustomerName' column from the 'Customers' table.
Syntax
SELECT ASCII(CustomerName) AS NumCodeOfFirstChar
FROM Customers;
Output
The query returns a table with a column 'NumCodeOfFirstChar' containing the ASCII value of the first character of each customer's name.
NumCodeOfFirstChar
------------------
65 --(Example: If the first character is 'A')
66 --(Example: If the first character is 'B')
...
Technical Details
The ASCII()
function is supported in:
- SQL Server (starting with version 2008)
- Azure SQL Database
- Azure SQL Data Warehouse
- Parallel Data Warehouse