Interview Question of the Week #055 – How to Convert ASCII to DECIMAL or DECIMAL to ASCII?

Question: How do you convert ASCII to DECIMAL or DECIMAL to ASCII?

Answer: 

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:
--Decimal to ASCII
SELECT CHAR(80)+CHAR(73)+CHAR(78)+CHAR(65)+CHAR(76) ASSQLAuthorityAuthor
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

Reference : Pinal Dave (https://blog.sqlauthority.com)

Previous Post
SQL SERVER – Script: Change Service Account Using WMI / SMO
Next Post
SQL SERVER – Why is My Query Switching to Row Processing and Not Doing Batch Processing?

Related Posts

4 Comments. Leave new

Leave a Reply

Menu