SQL CHAR Function

The CHAR function converts an integer to a single-byte character.

The returned character is based on the encoding in the current database collation.

Commonly used characters include: 9 (tab), 10 (line feed), and 13 (carriage return).

Example

#

This example returns single-byte characters for the given integer values.

SELECT CHAR(68) AS '68',
       CHAR(112) AS '112',
       CHAR(57) AS '57',
       CHAR(189) AS '189',
       CHAR(216) AS '216'
Result:  1 record
68 112 57 189 216
D p 9 ½ Ø

Syntax

Syntax of the CHAR function.

CHAR(integer)

integer -- an integer from 0 to 255. Any other value returns NULL.


More Examples

CHAR, text formatting

CUSTOMER
Id
FirstName
LastName
City
Country
Phone
Problem: List customers with their name on the first line and phone number on a second line.
SELECT FirstName + ' ' + LastName + CHAR(13) + 
       Phone AS Customer
  FROM Customer
Result:  91 records
Customer
Marias Anders
030-0074321
Ana Trujillo
(5) 555-4729
Antonio Moreno
(5) 555-3932
Thomas Hardy
(171) 555-7788
Christina Berglund
0921-12 34 65

You may also like



Guides


vsn 3.1