T-SQL NCHAR() Function
The T-SQL (Transact-SQL) NCHAR() function returns the Unicode character with the specified integer code, as defined by the Unicode standard.
Syntax
NCHAR(integer_code)
Parameters
integer_code |
Required. Specify integer whose Unicode character value is to be retrieved. |
Return Value
Returns the Unicode character with the specified integer code, as defined by the Unicode standard.
Example 1:
The example below shows the usage of NCHAR() function.
SELECT NCHAR(72); Result: 'H' SELECT NCHAR(69); Result: 'E' SELECT NCHAR(NULL); Result: NULL SELECT NCHAR('73'); Result: 'I'
Example 2:
Consider a database table called Sample with the following records:
Data | x1 | x2 | x3 |
---|---|---|---|
Data1 | 67 | 117 | 116 |
Data2 | 80 | 117 | 116 |
Data3 | 84 | 111 | 111 |
Data4 | 66 | 111 | 119 |
Data5 | 67 | 79 | 68 |
Data6 | 69 | 110 | 100 |
The statement given below can be used to get the string containing Unicode characters given by the code values specified by columns x1, x2 and x3.
SELECT *, NCHAR(x1) + NCHAR(x2) + NCHAR(x3) AS NCHAR_String FROM Sample;
The query will produce the following result:
Data | x1 | x2 | x3 | NCHAR_String |
---|---|---|---|---|
Data1 | 67 | 117 | 116 | Cut |
Data2 | 80 | 117 | 116 | Put |
Data3 | 84 | 111 | 111 | Too |
Data4 | 66 | 111 | 119 | Bow |
Data5 | 67 | 79 | 68 | COD |
Data6 | 69 | 110 | 100 | End |
❮ T-SQL Functions