SQL Server NCHAR Function


By:

The NCHAR function is used to get the actual character when the UNICODE value is provided.

Syntax

NCHAR(value)

Parameters

  • value - this is an integer value from 0 to 65535 that is used to find the Unicode character.

Simple NCHAR Example

The following example will show the Unicode character related to the value provided.

SELECT NCHAR(49) 
SELECT NCHAR(50) 
SELECT NCHAR(51) 
SELECT NCHAR(65) 
SELECT NCHAR(66)

We get the following values:

1
2
3
A
B

Get List of All NCHAR Values and Integer Value

The following will get a list of the code values and the corresponding Unicode character.

DECLARE @counter INT = 0
 
CREATE TABLE #NCharValues ([nchar] nchar(1), [unicode] int)
 
WHILE (@counter <= 144697)
BEGIN
   BEGIN TRY
      INSERT INTO #NCharValues
      SELECT NCHAR(@counter), UNICODE(NCHAR(@counter)) 
      SET @counter = @counter + 1
   END TRY
   BEGIN CATCH;
      SET @counter = @counter + 1
      IF @counter > 144697
      BEGIN
         BREAK
      END
   END CATCH
END
 
SELECT [UNICODE], [nchar] FROM #NCharValues
 
DROP TABLE #NCharValues

Here are a few rows from the query results.

unicode,nchar functions

Related Articles


Last Update: 11/15/2021




Comments For This Article





download














get free sql tips
agree to terms