CHAR(ASCIIValue) : Char function « String Functions « SQL Server / T-SQL Tutorial






2> -- Create temporary table for numbers:
3> Create Table #ASCIIVals (ASCIIValue SmallInt)
4> GO-- Insert numbers 0 - 127 into table:
1> Insert Into #ASCIIVals (ASCIIValue) Select 0
2> Insert Into #ASCIIVals (ASCIIValue) Select 1
3> Insert Into #ASCIIVals (ASCIIValue) Select 2
4> Insert Into #ASCIIVals (ASCIIValue) Select 3
5> Insert Into #ASCIIVals (ASCIIValue) Select 4
6> Insert Into #ASCIIVals (ASCIIValue) Select 123
7> Insert Into #ASCIIVals (ASCIIValue) Select 124
8> Insert Into #ASCIIVals (ASCIIValue) Select 125
9> Insert Into #ASCIIVals (ASCIIValue) Select 126
10> Insert Into #ASCIIVals (ASCIIValue) Select 127
11> GO-- Return all integer values and corresponding ASCII characters:

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)
1> SELECT ASCIIValue, CHAR(ASCIIValue) As Character FROM #ASCIIVals
2>
3> drop table #ASCIIVals;
4> GO
ASCIIValue Character
---------- ---------
         0
         1 ?
         2 ?
         3 ?
         4 ?
       123 {
       124 |
       125 }
       126 ~
       127 ?

(10 rows affected)








12.2.Char function
12.2.1.CHAR is the reverse of the ASCII function as it changes a numeric value in to an ASCII character.
12.2.2.CHAR(ASCIIValue)
12.2.3.CHAR(13)
12.2.4.A SELECT statement that uses the CHAR function to format output