By: Joe Gavin | Updated: 2019-04-26 | Comments | Related: > TSQL
Problem
The SQL Server CHAR String Function converts any of 256 the integer ASCII codes to a character value. It would be impossible to remember them all, so I put this document together to show the integer values along with their corresponding string values, plus some examples for an easy reference.
Solution
The following is a reference with some examples. The syntax is simply CHAR (integer) where integer is the integer value between 0 and 255.
The SQL was tested with SQL Server 2016 / US English.
Control Characters
ASCII codes 0 through 31 are non-printable, or control characters.
Integer Value | Character | Integer Value | Character | Integer Value | Character |
---|---|---|---|---|---|
0 | null | 12 | form feed | 24 | cancel |
1 | start of header | 13 | carriage return | 25 | end of medium |
2 | start of text | 14 | shift out | 26 | substitute |
3 | end of text | 15 | shift in | 27 | escape |
4 | end of transmission | 16 | data link escape | 28 | file separator |
5 | enquiry | 17 | device control 1 | 29 | group separator |
6 | acknowledge | 18 | device control 2 | 30 | record separator |
7 | bell | 19 | device control 3 | 31 | unit separator |
8 | backspace | 20 | device control 4 | ||
9 | horizontal tab | 21 | negative acknowledge | ||
10 | line feed | 22 | synchronize | ||
11 | vertical tab | 23 | end of trans. block |
Here are some commonly used control characters along with the output of them used in PRINT statements.
PRINT 'a' + CHAR(9) + 'b' -- horizontal tab PRINT 'a' + CHAR(10) + 'b' -- line feed PRINT 'a' + CHAR(11) + 'b' -- vertical tab PRINT 'a' + CHAR(13) + 'b' -- carriage return
SQL Server T-SQL Code | Result |
---|---|
PRINT 'a' + CHAR(9) + 'b' | a b |
PRINT 'a' + CHAR(10) + 'b' | a b |
PRINT 'a' + CHAR(11) + 'b' | a b |
PRINT 'a' + CHAR(13) + 'b' | a b |
Printable Characters
ASCII codes 32 through 127 are regular, printable characters.
Int Value | Character | Int Value | Character |
---|---|---|---|
32 | Space | 80 | Uppercase P |
33 | Exclamation mark | 81 | Uppercase Q |
34 | Double quotes (or speech marks) | 82 | Uppercase R |
35 | Number | 83 | Uppercase S |
36 | Dollar | 84 | Uppercase T |
37 | Per cent sign | 85 | Uppercase U |
38 | Ampersand | 86 | Uppercase V |
39 | Single quote | 87 | Uppercase W |
40 | Open parenthesis (or open bracket) | 88 | Uppercase X |
41 | Close parenthesis (or close bracket) | 89 | Uppercase Y |
42 | Asterisk | 90 | Uppercase Z |
43 | Plus | 91 | Opening bracket |
44 | Comma | 92 | Backslash |
45 | Hyphen | 93 | Closing bracket |
46 | Period, dot or full stop | 94 | Caret - circumflex |
47 | Slash or divide | 95 | Underscore |
48 | Zero | 96 | Grave accent |
49 | One | 97 | Lowercase a |
50 | Two | 98 | Lowercase b |
51 | Three | 99 | Lowercase c |
52 | Four | 100 | Lowercase d |
53 | Five | 101 | Lowercase e |
54 | Six | 102 | Lowercase f |
55 | Seven | 103 | Lowercase g |
56 | Eight | 104 | Lowercase h |
57 | Nine | 105 | Lowercase i |
58 | Colon | 106 | Lowercase j |
59 | Semicolon | 107 | Lowercase k |
60 | Less than (or open angled bracket) | 108 | Lowercase l |
61 | Equals | 109 | Lowercase m |
62 | Greater than (or close angled bracket) | 110 | Lowercase n |
63 | Question mark | 111 | Lowercase o |
64 | At symbol | 112 | Lowercase p |
65 | Uppercase A | 113 | Lowercase q |
66 | Uppercase B | 114 | Lowercase r |
67 | Uppercase C | 115 | Lowercase s |
68 | Uppercase D | 116 | Lowercase t |
69 | Uppercase E | 117 | Lowercase u |
70 | Uppercase F | 118 | Lowercase v |
71 | Uppercase G | 119 | Lowercase w |
72 | Uppercase H | 120 | Lowercase x |
73 | Uppercase I | 121 | Lowercase y |
74 | Uppercase J | 122 | Lowercase z |
75 | Uppercase K | 123 | Opening brace |
76 | Uppercase L | 124 | Vertical bar |
77 | Uppercase M | 125 | Closing brace |
78 | Uppercase N | 126 | Equivalency sign - tilde |
79 | Uppercase O | 127 | Delete |
Here are the printable characters along with the output of them used in PRINT statements.
PRINT 'a' + CHAR(32) + 'b' PRINT CHAR(33) PRINT CHAR(34) PRINT CHAR(35) PRINT CHAR(36) PRINT CHAR(37) PRINT CHAR(38) PRINT CHAR(39) PRINT CHAR(40) PRINT CHAR(41) PRINT CHAR(42) PRINT CHAR(32) PRINT CHAR(43) PRINT CHAR(44) PRINT CHAR(45) PRINT CHAR(46) PRINT CHAR(47) PRINT CHAR(48) PRINT CHAR(49) PRINT CHAR(50) PRINT CHAR(51) PRINT CHAR(52) PRINT CHAR(53) PRINT CHAR(54) PRINT CHAR(55) PRINT CHAR(56) PRINT CHAR(57) PRINT CHAR(58) PRINT CHAR(59) PRINT CHAR(60) PRINT CHAR(61) PRINT CHAR(62) PRINT CHAR(63) PRINT CHAR(64) PRINT CHAR(65) PRINT CHAR(66) PRINT CHAR(67) PRINT CHAR(68) PRINT CHAR(69) PRINT CHAR(70) PRINT CHAR(71) PRINT CHAR(72) PRINT CHAR(73) PRINT CHAR(74) PRINT CHAR(75) PRINT CHAR(76) PRINT CHAR(77) PRINT CHAR(78) PRINT CHAR(79) PRINT CHAR(80) PRINT CHAR(81) PRINT CHAR(82) PRINT CHAR(83) PRINT CHAR(84) PRINT CHAR(85) PRINT CHAR(86) PRINT CHAR(87) PRINT CHAR(88) PRINT CHAR(89) PRINT CHAR(90) PRINT CHAR(91) PRINT CHAR(92) PRINT CHAR(93) PRINT CHAR(94) PRINT CHAR(95) PRINT CHAR(96) PRINT CHAR(97) PRINT CHAR(98) PRINT CHAR(99) PRINT CHAR(100) PRINT CHAR(101) PRINT CHAR(102) PRINT CHAR(103) PRINT CHAR(104) PRINT CHAR(105) PRINT CHAR(106) PRINT CHAR(107) PRINT CHAR(108) PRINT CHAR(109) PRINT CHAR(110) PRINT CHAR(111) PRINT CHAR(112) PRINT CHAR(113) PRINT CHAR(114) PRINT CHAR(115) PRINT CHAR(116) PRINT CHAR(117) PRINT CHAR(118) PRINT CHAR(119) PRINT CHAR(120) PRINT CHAR(121) PRINT CHAR(122) PRINT CHAR(123) PRINT CHAR(124) PRINT CHAR(125) PRINT CHAR(126) PRINT CHAR(127)
SQL Server T-SQL Code | Result | SQL Server T-SQL Code | Result |
---|---|---|---|
PRINT CHAR(32) | a b | PRINT CHAR(80) | P |
PRINT CHAR(33) | ! | PRINT CHAR(81) | Q |
PRINT CHAR(34) | " | PRINT CHAR(82) | R |
PRINT CHAR(35) | # | PRINT CHAR(83) | S |
PRINT CHAR(36) | $ | PRINT CHAR(84) | T |
PRINT CHAR(37) | % | PRINT CHAR(85) | U |
PRINT CHAR(38) | & | PRINT CHAR(86) | V |
PRINT CHAR(39) | ' | PRINT CHAR(87) | W |
PRINT CHAR(40) | ( | PRINT CHAR(88) | X |
PRINT CHAR(41) | ) | PRINT CHAR(89) | Y |
PRINT CHAR(42) | * | PRINT CHAR(90) | Z |
PRINT CHAR(43) | + | PRINT CHAR(91) | [ |
PRINT CHAR(44) | , | PRINT CHAR(92) | \ |
PRINT CHAR(45) | - | PRINT CHAR(93) | ] |
PRINT CHAR(46) | . | PRINT CHAR(94) |
^ |
PRINT CHAR(47) | / | PRINT CHAR(95) | _ |
PRINT CHAR(48) | 0 | PRINT CHAR(96) |
` |
PRINT CHAR(49) | 1 | PRINT CHAR(97) | a |
PRINT CHAR(50) | 2 | PRINT CHAR(98) | b |
PRINT CHAR(51) | 3 | PRINT CHAR(99) | c |
PRINT CHAR(52) | 4 | PRINT CHAR(100) | d |
PRINT CHAR(53) | 5 | PRINT CHAR(101) | e |
PRINT CHAR(54) | 6 | PRINT CHAR(102) | f |
PRINT CHAR(55) | 7 | PRINT CHAR(103) | g |
PRINT CHAR(56) | 8 | PRINT CHAR(104) | h |
PRINT CHAR(57) | 9 | PRINT CHAR(105) | i |
PRINT CHAR(58) | : | PRINT CHAR(106) | j |
PRINT CHAR(59) | ; | PRINT CHAR(107) | k |
PRINT CHAR(60) | < | PRINT CHAR(108) | l |
PRINT CHAR(61) | = | PRINT CHAR(109) | m |
PRINT CHAR(62) | > | PRINT CHAR(110) | n |
PRINT CHAR(63) | ? | PRINT CHAR(111) | o |
PRINT CHAR(64) | @ | PRINT CHAR(112) | p |
PRINT CHAR(65) | A | PRINT CHAR(113) | q |
PRINT CHAR(66) | B | PRINT CHAR(114) | r |
PRINT CHAR(67) | C | PRINT CHAR(115) | s |
PRINT CHAR(68) | D | PRINT CHAR(116) | t |
PRINT CHAR(69) | E | PRINT CHAR(117) | u |
PRINT CHAR(70) | F | PRINT CHAR(118) | v |
PRINT CHAR(71) | G | PRINT CHAR(119) | w |
PRINT CHAR(72) | H | PRINT CHAR(120) | x |
PRINT CHAR(73) | I | PRINT CHAR(121) | y |
PRINT CHAR(74) | J | PRINT CHAR(122) | z |
PRINT CHAR(75) | K | PRINT CHAR(123) | { |
PRINT CHAR(76) | L | PRINT CHAR(124) | | |
PRINT CHAR(77) | M | PRINT CHAR(125) | } |
PRINT CHAR(78) | N | PRINT CHAR(126) | ~ |
PRINT CHAR(79) | O | PRINT CHAR(127) | |
Extended Characters
And finally, ASCII codes 128 through 255 are extended characters which give you an additional 128 characters.
Integer Value | Character | Integer Value | Character |
---|---|---|---|
128 | Euro sign | 192 | Latin capital letter A with grave |
129 | 193 | Latin capital letter A with acute | |
130 | Single low-9 quotation mark | 194 | Latin capital letter A with circumflex |
131 | Latin small letter f with hook | 195 | Latin capital letter A with tilde |
132 | Double low-9 quotation mark | 196 | Latin capital letter A with diaeresis |
133 | Horizontal ellipsis | 197 | Latin capital letter A with ring above |
134 | Dagger | 198 | Latin capital letter AE |
135 | Double dagger | 199 | Latin capital letter C with cedilla |
136 | Modifier letter circumflex accent | 200 | Latin capital letter E with grave |
137 | Per mille sign | 201 | Latin capital letter E with acute |
138 | Latin capital letter S with caron | 202 | Latin capital letter E with circumflex |
139 | Single left-pointing angle quotation | 203 | Latin capital letter E with diaeresis |
140 | Latin capital ligature OE | 204 | Latin capital letter I with grave |
141 | 205 | Latin capital letter I with acute | |
142 | Latin capital letter Z with caron | 206 | Latin capital letter I with circumflex |
143 | 207 | Latin capital letter I with diaeresis | |
144 | 208 | Latin capital letter ETH | |
145 | Left single quotation mark | 209 | Latin capital letter N with tilde |
146 | Right single quotation mark | 210 | Latin capital letter O with grave |
147 | Left double quotation mark | 211 | Latin capital letter O with acute |
148 | Right double quotation mark | 212 | Latin capital letter O with circumflex |
149 | Bullet | 213 | Latin capital letter O with tilde |
150 | En dash | 214 | Latin capital letter O with diaeresis |
151 | Em dash | 215 | Multiplication sign |
152 | Small tilde | 216 | Latin capital letter O with slash |
153 | Trade mark sign | 217 | Latin capital letter U with grave |
154 | Latin small letter S with caron | 218 | Latin capital letter U with acute |
155 | Single right-pointing angle quotation mark | 219 | Latin capital letter U with circumflex |
156 | Latin small ligature oe | 220 | Latin capital letter U with diaeresis |
157 | 221 | Latin capital letter Y with acute | |
158 | Latin small letter z with caron | 222 | Latin capital letter THORN |
159 | Latin capital letter Y with diaeresis | 223 | Latin small letter sharp s - ess-zed |
160 | Non-breaking space | 224 | Latin small letter a with grave |
161 | Inverted exclamation mark | 225 | Latin small letter a with acute |
162 | Cent sign | 226 | Latin small letter a with circumflex |
163 | Pound sign | 227 | Latin small letter a with tilde |
164 | Currency sign | 228 | Latin small letter a with diaeresis |
165 | Yen sign | 229 | Latin small letter a with ring above |
166 | Pipe, Broken vertical bar | 230 | Latin small letter ae |
167 | Section sign | 231 | Latin small letter c with cedilla |
168 | Spacing diaeresis - umlaut | 232 | Latin small letter e with grave |
169 | Copyright sign | 233 | Latin small letter e with acute |
170 | Feminine ordinal indicator | 234 | Latin small letter e with circumflex |
171 | Left double angle quotes | 235 | Latin small letter e with diaeresis |
172 | Not sign | 236 | Latin small letter i with grave |
173 | Soft hyphen | 237 | Latin small letter i with acute |
174 | Registered trade mark sign | 238 | Latin small letter i with circumflex |
175 | Spacing macron - overline | 239 | Latin small letter i with diaeresis |
176 | Degree sign | 240 | Latin small letter eth |
177 | Plus-or-minus sign | 241 | Latin small letter n with tilde |
178 | Superscript two - squared | 242 | Latin small letter o with grave |
179 | Superscript three - cubed | 243 | Latin small letter o with acute |
180 | Acute accent - spacing acute | 244 | Latin small letter o with circumflex |
181 | Micro sign | 245 | Latin small letter o with tilde |
182 | Pilcrow sign - paragraph sign | 246 | Latin small letter o with diaeresis |
183 | Middle dot - Georgian comma | 247 | Division sign |
184 | Spacing cedilla | 248 | Latin small letter o with slash |
185 | Superscript one | 249 | Latin small letter u with grave |
186 | Masculine ordinal indicator | 250 | Latin small letter u with acute |
187 | Right double angle quotes | 251 | Latin small letter u with circumflex |
188 | Fraction one quarter | 252 | Latin small letter u with diaeresis |
189 | Fraction one half | 253 | Latin small letter y with acute |
190 | Fraction three quarters | 254 | Latin small letter thorn |
191 | Inverted question mark | 255 | Latin small letter y with diaeresis |
PRINT CHAR(128) PRINT CHAR(129) PRINT CHAR(130) PRINT CHAR(131) PRINT CHAR(132) PRINT CHAR(133) PRINT CHAR(134) PRINT CHAR(135) PRINT CHAR(136) PRINT CHAR(137) PRINT CHAR(138) PRINT CHAR(139) PRINT CHAR(140) PRINT CHAR(141) PRINT CHAR(142) PRINT CHAR(143) PRINT CHAR(144) PRINT CHAR(145) PRINT CHAR(146) PRINT CHAR(147) PRINT CHAR(148) PRINT CHAR(149) PRINT CHAR(150) PRINT CHAR(151) PRINT CHAR(152) PRINT CHAR(153) PRINT CHAR(154) PRINT CHAR(155) PRINT CHAR(156) PRINT CHAR(157) PRINT CHAR(158) PRINT CHAR(159) PRINT CHAR(160) PRINT CHAR(161) PRINT CHAR(162) PRINT CHAR(163) PRINT CHAR(164) PRINT CHAR(165) PRINT CHAR(166) PRINT CHAR(167) PRINT CHAR(168) PRINT CHAR(169) PRINT CHAR(170) PRINT CHAR(171) PRINT CHAR(172) PRINT CHAR(173) PRINT CHAR(174) PRINT CHAR(175) PRINT CHAR(176) PRINT CHAR(177) PRINT CHAR(178) PRINT CHAR(179) PRINT CHAR(180) PRINT CHAR(181) PRINT CHAR(182) PRINT CHAR(183) PRINT CHAR(184) PRINT CHAR(185) PRINT CHAR(186) PRINT CHAR(187) PRINT CHAR(188) PRINT CHAR(189) PRINT CHAR(190) PRINT CHAR(191) PRINT CHAR(192) PRINT CHAR(193) PRINT CHAR(194) PRINT CHAR(195) PRINT CHAR(196) PRINT CHAR(197) PRINT CHAR(198) PRINT CHAR(199) PRINT CHAR(200) PRINT CHAR(201) PRINT CHAR(202) PRINT CHAR(203) PRINT CHAR(204) PRINT CHAR(205) PRINT CHAR(206) PRINT CHAR(207) PRINT CHAR(208) PRINT CHAR(209) PRINT CHAR(210) PRINT CHAR(211) PRINT CHAR(212) PRINT CHAR(213) PRINT CHAR(214) PRINT CHAR(215) PRINT CHAR(216) PRINT CHAR(217) PRINT CHAR(218) PRINT CHAR(219) PRINT CHAR(220) PRINT CHAR(221) PRINT CHAR(222) PRINT CHAR(223) PRINT CHAR(224) PRINT CHAR(225) PRINT CHAR(226) PRINT CHAR(227) PRINT CHAR(228) PRINT CHAR(229) PRINT CHAR(230) PRINT CHAR(231) PRINT CHAR(232) PRINT CHAR(233) PRINT CHAR(234) PRINT CHAR(235) PRINT CHAR(236) PRINT CHAR(237) PRINT CHAR(238) PRINT CHAR(239) PRINT CHAR(240) PRINT CHAR(241) PRINT CHAR(242) PRINT CHAR(243) PRINT CHAR(244) PRINT CHAR(245) PRINT CHAR(246) PRINT CHAR(247) PRINT CHAR(248) PRINT CHAR(249) PRINT CHAR(250) PRINT CHAR(251) PRINT CHAR(252) PRINT CHAR(253) PRINT CHAR(254) PRINT CHAR(255)
SQL Server T-SQL Code | Result | SQL Server T-SQL Code | Result |
---|---|---|---|
PRINT CHAR(128) | € | PRINT CHAR(192) | À |
PRINT CHAR(129) | PRINT CHAR(193) | Á | |
PRINT CHAR(130) | ‚ | PRINT CHAR(194) | Â |
PRINT CHAR(131) | ƒ | PRINT CHAR(195) | Ã |
PRINT CHAR(132) | „ | PRINT CHAR(196) | Ä |
PRINT CHAR(133) | … | PRINT CHAR(197) | Å |
PRINT CHAR(134) | † | PRINT CHAR(198) | Æ |
PRINT CHAR(135) | ‡ | PRINT CHAR(199) | Ç |
PRINT CHAR(136) | ˆ | PRINT CHAR(200) | È |
PRINT CHAR(137) | ‰ | PRINT CHAR(201) | É |
PRINT CHAR(138) | Š | PRINT CHAR(202) | Ê |
PRINT CHAR(139) | ‹ | PRINT CHAR(203) | Ë |
PRINT CHAR(140) | Œ | PRINT CHAR(204) | Ì |
PRINT CHAR(141) | PRINT CHAR(205) | Í | |
PRINT CHAR(142) | PRINT CHAR(206) | Î | |
PRINT CHAR(143) | PRINT CHAR(207) | Ï | |
PRINT CHAR(144) | PRINT CHAR(208) | Ð | |
PRINT CHAR(145) | ‘ | PRINT CHAR(209) | Ñ |
PRINT CHAR(146) | ’ | PRINT CHAR(210) | Ò |
PRINT CHAR(147) | “ | PRINT CHAR(211) | Ó |
PRINT CHAR(148) | ” | PRINT CHAR(212) | Ô |
PRINT CHAR(149) | • | PRINT CHAR(213) | Õ |
PRINT CHAR(150) | – | PRINT CHAR(214) | Ö |
PRINT CHAR(151) | — | PRINT CHAR(215) | × |
PRINT CHAR(152) | ˜ | PRINT CHAR(216) | Ø |
PRINT CHAR(153) | ™ | PRINT CHAR(217) | Ù |
PRINT CHAR(154) | š | PRINT CHAR(218) | Ú |
PRINT CHAR(155) | › | PRINT CHAR(219) | Û |
PRINT CHAR(156) | œ | PRINT CHAR(220) | Ü |
PRINT CHAR(157) | PRINT CHAR(221) | Ý | |
PRINT CHAR(158) | PRINT CHAR(222) | Þ | |
PRINT CHAR(159) | Ÿ | PRINT CHAR(223) | ß |
PRINT CHAR(160) | PRINT CHAR(224) | à | |
PRINT CHAR(161) | ¡ | PRINT CHAR(225) | á |
PRINT CHAR(162) | ¢ | PRINT CHAR(226) | â |
PRINT CHAR(163) | £ | PRINT CHAR(227) | ã |
PRINT CHAR(164) | ¤ | PRINT CHAR(228) | ä |
PRINT CHAR(165) | ¥ | PRINT CHAR(229) | å |
PRINT CHAR(166) | ¦ | PRINT CHAR(230) | æ |
PRINT CHAR(167) | § | PRINT CHAR(231) | ç |
PRINT CHAR(168) | ¨ | PRINT CHAR(232) | è |
PRINT CHAR(169) | © | PRINT CHAR(233) | é |
PRINT CHAR(170) | ª | PRINT CHAR(234) | ê |
PRINT CHAR(171) | « | PRINT CHAR(235) | ë |
PRINT CHAR(172) | ¬ | PRINT CHAR(236) | ì |
PRINT CHAR(173) | | PRINT CHAR(237) | í |
PRINT CHAR(174) | ® | PRINT CHAR(238) | î |
PRINT CHAR(175) | ¯ | PRINT CHAR(239) | ï |
PRINT CHAR(176) | ° | PRINT CHAR(240) | ð |
PRINT CHAR(177) | ± | PRINT CHAR(241) | ñ |
PRINT CHAR(178) | ² | PRINT CHAR(242) | ò |
PRINT CHAR(179) | ³ | PRINT CHAR(243) | ó |
PRINT CHAR(180) | ´ | PRINT CHAR(244) | ô |
PRINT CHAR(181) | µ | PRINT CHAR(245) | õ |
PRINT CHAR(182) | ¶ | PRINT CHAR(246) | ö |
PRINT CHAR(183) | · | PRINT CHAR(247) | ÷ |
PRINT CHAR(184) | ¸ | PRINT CHAR(248) | ø |
PRINT CHAR(185) | ¹ | PRINT CHAR(249) | ù |
PRINT CHAR(186) | º | PRINT CHAR(250) | ú |
PRINT CHAR(187) | » | PRINT CHAR(251) | û |
PRINT CHAR(188) | ¼ | PRINT CHAR(252) | ü |
PRINT CHAR(189) | ½ | PRINT CHAR(253) | ý |
PRINT CHAR(190) | ¾ | PRINT CHAR(254) | þ |
PRINT CHAR(191) | ¿ | PRINT CHAR(255) | ÿ |
Next Steps
Following are some links with more information on the CHAR function:
- Generating A Password in SQL Server with T-SQL from Random Characters
- SQL Server random numerics data generation using CLR
- SQL Server CHAR (Transact-SQL)
- How to replace ASCII special characters in SQL Server
About the author
This author pledges the content of this article is based on professional experience and not AI generated.
View all my tips
Article Last Updated: 2019-04-26