Convert binary to varchar

10,949

Solution 1

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

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

Solution 2

this also works for me :

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

just change your value with varbinary_val

Share:
10,949
SujithTee
Author by

SujithTee

Updated on June 14, 2022

Comments

  • SujithTee
    SujithTee almost 2 years

    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.

  • SujithTee
    SujithTee almost 7 years
    But the 0x is trimmed from the output.I need the output include that
  • Esteban P.
    Esteban P. almost 7 years
    @SujithTee i updated my post. I just changed the third parameter of convert from 2 to 1