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 f
From SQL Server 2005 onwards CONVERT does what you want:
CONVERT(varbinary(2000), '00001340132401324...', 2)
The styles for converting to/from binary are:
For converting characters to binary in format 0:
char
or varchar
data (e.g. ASCII, ISO-8859-1) become binary bytes. For single character encodings this means one byte per character.nchar
or nvarchar
data (i.e. UTF-16) become two bytes each, in big-endian format, so N'ABC'
becomes 0x410042004300
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: