NCHAR String Function

The NCHAR string function returns the Unicode character with the specified integer code, as defined by the Unicode standard. The syntax of the NCHAR string function is as follows:

NCHAR ( < integer_expression > )

Arguments

integer_expression

When the collation of the database does not contain the Supplementary Character (SC) flag, this is a positive integer from 0 through 65535 (0 through 0xFFFF). If a value outside this range is specified, NULL is returned.

When the collation of the database supports the SC flag, this is a positive integer from 0 through 1114111 (0 through 0x10FFFF). If a value outside this range is specified, NULL is returned.

Return Types

nchar(1) when the default database collation does not support supplementary characters.

nvarchar(2) when the default database collation supports supplementary characters.

Sample Uses of the NCHAR Function

Here are sample uses of the NCHAR string function

Usage #1 : Display Zodiac Signs

SELECT [Code], [Zodiac], NCHAR([Code]) AS [Sign]
FROM (VALUES (9800, 'Aries'), (9801, 'Taurus'), (9802, 'Gemini'),
             (9803, 'Cancer'), (9804, 'Leo'), (9805, 'Virgo'),
             (9806, 'Libra'), (9807, 'Scorpio'), (9808, 'Sagitarrius'),
             (9809, 'Capricorn'), (9810, 'Aquarius'), (9811, 'Pisces'))
AS [Zodiac Signs] ( [Code], [Zodiac] );
CodeZodiacSign
9800Aries
9801Taurus
9802Gemini
9803Cancer
9804Leo
9805Virgo
9806Libra
9807Scorpio
9808Sagitarrius
9809Capricorn
9810Aquarius
9811Pisces

Usage #2 : Display Card Suits

SELECT [Code], [SuitName], NCHAR([Code]) AS [Suit]
FROM (VALUES (9824, 'Spade (Shaded)'), (9825, 'Heart'), (9826, 'Diamond'),
             (9827, 'Club (Shaded)'), (9828, 'Spade'), (9829, 'Heart (Shaded)'),
             (9830, 'Diamond (Shaded)'), (9831, 'Club'))
AS [Card Suits] ( [Code], [SuitName] );
CodeSuitNameSuit
9824Spade (Shaded)
9825Heart
9826Diamond
9827Club (Shaded)
9828Spade
9829Heart (Shaded)
9830Diamond (Shaded)
9831Club

Usage #3 : Display Chess Pieces

SELECT [Code], [Piece], NCHAR([Code]) AS [Image]
FROM (VALUES (9812, 'White King'), (9813, 'White Queen'), (9814, 'White Rook'),
             (9815, 'White Bishop'), (9816, 'White Knight'), (9817, 'White Pawn'),
             (9818, 'Black King'), (9819, 'Black Queen'), (9820, 'Black Rook'),
             (9821, 'Black Bishop'), (9822, 'Black Knight'), (9823, 'Black Pawn'))
AS [Chess Pieces] ( [Code], [Piece] );
CodePieceImage
9812White King
9813White Queen
9814White Rook
9815White Bishop
9816White Knight
9817White Pawn
9818Black King
9819Black Queen
9820Black Rook
9821Black Bishop
9822Black Knight
9823Black Pawn

Usage #4 : Display Musical Symbols

SELECT [Code], [SymbolName], NCHAR([Code]) AS [Symbol]
FROM (VALUES (9833, 'Quarter Note'), (9834, 'Eighth Note'), (9835, 'Double Eighth Note'),
             (9836, 'Sixteenth Note'), (9837, 'Flat'), (9838, 'Natural'), (9839, 'Sharp'))
AS [Music Symbol] ( [Code], [SymbolName] );
CodeSymbolNameSymbol
9833Quarter Note
9834Eighth Note
9835Double Eighth Note
9836Sixteenth Note
9837Flat
9838Natural
9839Sharp

Usage #5 : Display Apply Keys Icons

SELECT [Code], [KeyName], NCHAR([Code]) AS [Symbol]
FROM (VALUES (8984, 'Command or Cmd'), (8963, 'Control or Ctrl or Ctl'),
             (8997, 'Option or Opt'), (8679, 'Shift'),
             (8682, 'Caps Lock'), (9167, 'Eject'),
             (8617, 'Carriage Return'), (8629, 'Carriage Return'),
             (9166, 'Carriage Return'), (8996, 'Enter'),
             (9003, 'Delete, Backspace'), (8998, 'Forward Delete'),
             (9099, 'Escape, Esc'), (8594, 'Right Arrow'),
             (8592, 'Left Arrow'), (8593, 'Up Arrow'),
             (8595, 'Down Arrow'), (8670, 'Page Up, PgUp'),
             (8671, 'Page Down, PgDn'), (8598, 'Home'),
             (8600, 'End'), (8999, 'Clear'),
             (8677, 'Tab, Tab Right, Horizontal Tab'),
             (8676, 'Shift Tab, Tab Left, Back Tab'),
             (9250, 'Space, Blank'), (9251, 'Space, Blank'))
AS [Apple Keys] ( [Code], [KeyName]);
CodeKeyNameSymbol
8984Command or Cmd
8963Control or Ctrl or Ctl
8997Option or Opt
8679Shift
8682Caps Lock
9167Eject
8617Carriage Return
8629Carriage Return
9166Carriage Return
8996Enter
9003Delete, Backspace
8998Forward Delete
9099Escape, Esc
8594Right Arrow
8592Left Arrow
8593Up Arrow
8595Down Arrow
8670Page Up, PgUp
8671Page Down, PgDn
8598Home
8600End
8999Clear
8677Tab, Tab Right, Horizontal Tab
8676Shift Tab, Tab Left, Back Tab
9250Space, Blank
9251Space, Blank