Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Select integer column as corresponding letter of the alphabet

I have an int column that contains values no larger than about 20. I want to select as its corresponding upper case letter of the alphabet:

1 = A
2 = B
3 = C
...

I don’t care what happens after Z because the column doesn’t contain larger values. Is there a simple way to do this with a SQL query, to convert to a single-byte character like this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Add 64 to your integer and you have the ASCII value of the letter you want.

mysql> select CHAR(1+64);
+------------+
| CHAR(1+64) |
+------------+
| A          |
+------------+

Read https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_char

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading