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] );
9800 | Aries | ♈ |
9801 | Taurus | ♉ |
9802 | Gemini | ♊ |
9803 | Cancer | ♋ |
9804 | Leo | ♌ |
9805 | Virgo | ♍ |
9806 | Libra | ♎ |
9807 | Scorpio | ♏ |
9808 | Sagitarrius | ♐ |
9809 | Capricorn | ♑ |
9810 | Aquarius | ♒ |
9811 | Pisces | ♓ |
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] );
9824 | Spade (Shaded) | ♠ |
9825 | Heart | ♡ |
9826 | Diamond | ♢ |
9827 | Club (Shaded) | ♣ |
9828 | Spade | ♤ |
9829 | Heart (Shaded) | ♥ |
9830 | Diamond (Shaded) | ♦ |
9831 | Club | ♧ |
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] );
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 | ♟ |
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] );
9833 | Quarter Note | ♩ |
9834 | Eighth Note | ♪ |
9835 | Double Eighth Note | ♫ |
9836 | Sixteenth Note | ♬ |
9837 | Flat | ♭ |
9838 | Natural | ♮ |
9839 | Sharp | ♯ |
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]);
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 | ␣ |