SQL Server UNICODE() Function
The SQL Server (Transact-SQL) UNICODE() function returns the numeric unicode code point corresponding to the first character of the specified string.
Syntax
UNICODE(character)
Parameters
character |
Required. Specify the character to return the unicode code point for. If more than one character is entered, the function will only return the value for the first character. |
Return Value
Returns the unicode code point of a character.
Example 1:
The example below shows the usage of UNICODE() function.
SELECT UNICODE('A'); Result: 65 SELECT UNICODE(1); Result: 49 SELECT UNICODE('AlphaCodingSkills.com'); Result: 65 SELECT UNICODE(123); Result: 49 SELECT UNICODE('@gmail.com'); Result: 64
Example 2:
Consider a database table called Employee with the following records:
EmpID | Name | City |
---|---|---|
1 | John | London |
2 | Marry | New York |
3 | Jo | Paris |
4 | Kim | Amsterdam |
5 | Ramesh | New Delhi |
6 | Huang | Beijing |
In the query below, the UNICODE() function is used to get the unicode code point of the first character of Name column value of Employee table.
SELECT *, UNICODE(Name) AS UNICODE_Val FROM Employee;
This will produce the result as shown below:
EmpID | Name | City | UNICODE_Val |
---|---|---|---|
1 | John | London | 74 |
2 | Marry | New York | 77 |
3 | Jo | Paris | 74 |
4 | Kim | Amsterdam | 75 |
5 | Ramesh | New Delhi | 82 |
6 | Huang | Beijing | 72 |
❮ SQL Server Functions