Follow sqlserver-dba.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

SQLServer-DBA.com Links

Dba_db2_button

dba-ninja.com

SQL Server DBA Jobs

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

21 December,2021 by Tom Collins

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

 

 


Author: Tom Collins (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on How to return the character values based on ASCII character number values


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer