1

I have an image stored in a table as a base64 encoded string. I have to convert it to a hexadecimal format and copy the value into another table. So i am looking for a way to do this in SQL

I tried it like this, but it did not work (I tested the result using an online converter)

select 
    cast(cast(@base64value as varchar(max)) as varbinary(max))

To clarify i want to convert base 64 to hexadecimal.

Tahdiul Haq
  • 245
  • 3
  • 11
  • 2
    Do you want hex of the value or of the original binary? – Joe C Nov 16 '17 at 21:00
  • If you want to get the file out of the database see this post https://stackoverflow.com/questions/14638245/how-to-export-base64-to-file – 1010 Nov 16 '17 at 22:16
  • I want the hex of the value. Also i dont want to get the file out of the database. I have to convert it to hex and copy it into another table – Tahdiul Haq Nov 17 '17 at 14:50
  • Possible duplicate of [Base64 encoding in SQL Server 2005 T-SQL](https://stackoverflow.com/questions/5082345/base64-encoding-in-sql-server-2005-t-sql) – Jeroen Mostert Nov 17 '17 at 15:02
  • 4
    i figured it out: `CAST( @base64value as XML ).value('.','varbinary(max)')` – Tahdiul Haq Nov 21 '17 at 19:46

0 Answers0