When I run the sql query I got something like this :
Disallowed implicit conversion from data type varchar to data type varbinary.... Use the CONVERT function to run this query. (severity 16)`
The data I want to insert looks like
'00001200000000000010000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...FFF'
How to done this query?
Query looks like :
UPDATE <table> SET VARBINARY_DATA = '00001200000000000010000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF....' WHERE ID = 12
From SQL Server 2005 onwards CONVERT does what you want:
The styles for converting to/from binary are:
For converting characters to binary in format 0:
char
orvarchar
data (e.g. ASCII, ISO-8859-1) become binary bytes. For single character encodings this means one byte per character.nchar
ornvarchar
data (i.e. UTF-16) become two bytes each, in big-endian format, soN'ABC'
becomes0x410042004300
For converting hex to binary in formats 1 and 2:
See MSDN:
If you need UTF-8 please see my answer here for a UDF which will convert text to UTF-8: