SQL Server UNICODE() Function

The UNICODE() function in SQL Server returns the Unicode code point for the first character of a string. Unicode is an international encoding standard that assigns a unique number to each character.



UNICODE(): Definition and Usage

UNICODE() is helpful when you need to work with the underlying numerical representation of characters, especially when dealing with international character sets or performing character-by-character comparisons. It only considers the very first character in the input string; any subsequent characters are ignored. The returned value is an integer.

Syntax

Syntax

UNICODE(character_expression)
      

Parameter Values

Parameter Description
character_expression The string (nchar or varchar) for which you want the Unicode value of its first character. This is required.

Examples

Getting the Unicode Value of a Character

This example shows how to get the Unicode value for the first character ('A') of the string 'Atlanta'.

Syntax

SELECT UNICODE('Atlanta');
      
Output

65
      

Getting Unicode Values from a Column

This example retrieves the Unicode value of the first character in the 'CustomerName' column for each customer in the 'Customers' table (assuming a table named 'Customers' exists with a 'CustomerName' column).

Syntax

SELECT UNICODE(CustomerName) AS UnicodeOfFirstChar
FROM Customers;
      
Output

UnicodeOfFirstChar
-------------------
(The Unicode value of the first character of each CustomerName will be displayed here.)
      

**Note:** The example outputs assume the existence of a `Customers` table with a `CustomerName` column. The specific Unicode values in the second example's output will depend on the first character of each customer's name in your table. If a `CustomerName` value is `NULL`, the output for that row will also be `NULL`.