Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert varchar to hexadecimal in sql server

I want a function to convert a varchar to hexadecimal in sql server. Please help me.

P.S. I will use unhex() in Hive to try to get the original value back. This is because my data contains special characters and backslash and the HIVE external table does not recognise it

like image 934
Srinivas Avatar asked Sep 09 '16 10:09

Srinivas


2 Answers

You can try to use CONVERT function:

SELECT CONVERT(VARBINARY(MAX), 'myText') 

Output:

0x6D7954657874
like image 69
Rahul Tripathi Avatar answered Sep 22 '22 07:09

Rahul Tripathi


you can use

select try_convert(varbinary,varcharcolumn)
like image 45
Kannan Kandasamy Avatar answered Sep 24 '22 07:09

Kannan Kandasamy