0

I have a table with column name Logo which has a datatype nvarchar(max) but the content is already in Base64 format. I want to move data from this column to another column which has a data type varbinary(max). If i use convert function it converts the logo Byte to varbinary which was actually in byte. How can i do this. Such as in the Logo column which has nvarchar(max) data type i have this -

'iVBORw0KGgoAAAANSUhEUgAAAFoAAABaCAYAAAA4qEECAAAACXBI......'

and i want to move exactly the same value to another column which has a data type varbinary(max).

Thanx in advance

Jishan
  • 169
  • 1
  • 6
  • 18
  • I have no idea what you mean by "the content is already in Byte". – Damien_The_Unbeliever Mar 03 '20 at 11:39
  • Does this answer your question? [Base64 encoding in SQL Server 2005 T-SQL](https://stackoverflow.com/questions/5082345/base64-encoding-in-sql-server-2005-t-sql) – Jeroen Mostert Mar 03 '20 at 11:42
  • Maybe this will help: https://stackoverflow.com/questions/14539445/change-column-from-varcharmax-to-varbinarymax – VBoka Mar 03 '20 at 11:43
  • See the duplicate, it tells you how to convert Base64 in T-SQL. Also, a "sample" just means that -- you don't have to post the complete string, which makes the question unreadable :-P – Jeroen Mostert Mar 03 '20 at 11:55
  • This might help. During convert just use 1 which is important. https://dba.stackexchange.com/questions/63743/converting-a-varchar-to-varbinary – Pankaj_Dwivedi Mar 03 '20 at 11:58
  • @Pankaj_Dwivedi if i use 1 in convert function style paramter i got this error 'Error converting data type nvarchar to varbinary' – Jishan Mar 03 '20 at 12:02

1 Answers1

1

I am reading between the lines here, but I think the OP is saying that have data in a varchar column that has values like '0x1A23494947D324B'. As a result something like SELECT CONVERT(varbinary,'0x1234'); doesn't return what the OP expects (0x307831323334).

You need to use a style code here, to let SQL Server know that the value is already in a varbinary format:

SELECT CONVERT(varbinary(MAX),'0x1234',1);
Thom A
  • 88,727
  • 11
  • 45
  • 75