How to convert String to Hex and vice versa?

As you know, in MySQL we have HEX and UNHEX, for example, when I write like this:

select hex("Ali"); 

conversion result: 416C69

and unhex looks like this: select unhex("416C69");

In MSSQL I cannot convert this, could you give me an example for both of them ???

Thanks a lot...

+4
source share
1 answer

I think this should work

 SELECT hex(CAST("Ali" AS VARBINARY)) AS Expr1 

for the contrary

 select CONVERT(varbinary(max), "416C69"); 

This is a conversion to varbinary, then you can convert varbinary to varchar

Convert string to HEX in SQL

http://blogs.msdn.com/b/sqltips/archive/2008/07/02/converting-from-hex-string-to-varbinary-and-vice-versa.aspx

+7
source

Source: https://habr.com/ru/post/1384077/


All Articles