The rawtohex() function converts a character string into the ASCII hexadecimal representation.
varchar = rawtohex(varchar input);
nvarchar = rawtohex(nvarchar input, [int unicode]);
The input value specifies the varchar or nvarchar string to convert.
The unicode value converts the input data into UTF-8 or Unicode values. A value of 0 converts the input string to UTF-8 values, and a value of 1 converts the string to Unicode values. The default is 0.
select rawtohex('hello');
RAWTOHEX
------------
68656C6C6F
(1 row)