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
This is only a preview. Your comment has not yet been posted.
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.
Posted by: |