In this blog post we will see how we can convert ASCII to Decimal and Decimal to ASCII. In simple words, we will see the decimal and ASCII conversion.
ASCII – Returns the ASCII code value of the leftmost character of a character expression.
CHAR – Fixed-length non-Unicode character data with length of n bytes.
Examples of Decimal and ASCII Conversion:
----Decimal to ASCII SELECT CHAR(80)+CHAR(73)+CHAR(78)+CHAR(65)+CHAR(76) AS SQLAuthorityAuthor GO ----ASCII to Decimal SELECT ASCII('P') AS SQLAuthorityAuthor UNION ALL SELECT ASCII('I') UNION ALL SELECT ASCII('N') UNION ALL SELECT ASCII('A') UNION ALL SELECT ASCII('L') GO
Here is the result set, when we execute the script displayed above:
I remember a story about the time when I was studying in school. At that time we used to remember the entire DECIMAL to ASCII Conversion table, so when we are asked a mathematical problem in our exam in school, we were able to do that efficiently and faster than the traditional methods. When I was writing this blog post, it reminded my old school time and I wish we had access to SQL Server during exam. Anyway, that is an old story, I hope that you will find this blog post help for your current business problem.
Reference : Pinal Dave (https://blog.sqlauthority.com)