Convert binary to varchar

时间:2017-07-12 07:58:01

标签: sql sql-server string binary varchar

I need to change the binary output to varchar(string), but it must same as to be the binary output. But while converting the binary(hex) value to varchar, empty set will be returned. Kindly help me.

E.x

If this is my binary value 0x24000000008B0100000000.

I need the same 0x24000000008B0100000000 output after converting it into string.

3 个答案:

答案 0 :(得分:4)

declare @val binary(20)
set @val=0x24000000008B0100000000

select @val, CONVERT(varchar(max),@val,1)

答案 1 :(得分:3)

this also works for me :

SELECT CONVERT(VARCHAR(1000), varbinary_val, 1);

just change your value with varbinary_val

答案 2 :(得分:0)

should work like:

DECLARE @a BINARY(20) = 0x24000000008B0100000000
SELECT  CONVERT(varchar(max),@a,1), @a