Quantcast
Channel: SQL Server DBA
Viewing all articles
Browse latest Browse all 80

How to return the character values based on ASCII character number values

$
0
0

Question: How can I view all the character values based on the ASCII character number values? 

I can do something like : SELECT CHAR(65) and return "A"  - but I'd like to list out all the characters.

Answer: This examples uses  ASCII and CHAR to print ASCII values 

 The Microsoft doc quotes CHAR as " Returns the single-byte character with the specified integer code, as defined by the character set and encoding of the default collation of the current database"

 

;WITH NumberValues AS
(
    SELECT 1 AS Number
    UNION ALL
    SELECT Number+1
        FROM NumberValues
        WHERE Number<255
)
SELECT Number,CHAR(Number) as CharacterValue FROM NumberValues
OPTION (MAXRECURSION 255)

 

If you execute this on a sql server , you'll get back 255 rows with the relevant characters associated with the ASCII character number values

 

 

Read more ascii , encoding and sql collation

How to bcp export file with encoding ascii

How to specify encoding when creating Powershell text file using Out-file

A focus on SQL Server Collations and code page

 

 


Viewing all articles
Browse latest Browse all 80

Trending Articles