Article ID: 104829 - Last Review: February 22, 2005 - Revision: 3.2 INFO: Converting Binary Data to Hexadecimal StringThis article was previously published under Q104829 SUMMARY
SQL Server does not have built-in Transact-SQL command for converting
binary data to a hexadecimal string.
MORE INFORMATION
The Transact-SQL CONVERT command converts binary data to character data
in a one byte to one character fashion. SQL Server takes each byte of
the source binary data, converts it to an integer value, then uses that
integer value as the ASCII value for the destination character data.
This behavior applies to the binary, varbinary, and timestamp datatypes.
For example, binary value 00001111 (0x0F in hexadecimal) is converted into its integer equivalent which is 15, then converted to the character that corresponds to ASCII value 15, which is unreadable. The following stored procedure can be used to return a character string which contains the hexadecimal representation of a binary value: For example, when the following command batch is executed with ISQL: it returns output similar to the following:
sp_hexadecimal
------------------------------------------------------------------
0x01000000a60b0000
(1 row affected)
isql
------------------------------------------------------------------
0x01000000a60b0000
(1 row affected)
APPLIES TO
| Article Translations
|
Back to the top
