type conversion - SQL Server 2008 convert varchar to varbinary -


i try import image data sql server 2008 db code this:

insert [tab] (id_photo,photo) values(     cast('333efb54-7062-e043-f088-fe0a916c0297' uniqueidentifier),     convert(varbinary(max),'0xffd8ffe000') ) 

the string dummy when make insert found in database

0x307846464438464645303030 

which isn't expected. know have done wrong?

the issue here string -- '0xffd8ffe000' -- being converted varbinary, , each character -- first 0, x, f, , on -- "converted" hex representation:

character   --  hex value   0               30   x               78   f               46   f               46   d               44   8               38   f               46   f               46   e               45   0               30   0               30   0               30 

so, 0xffd8ffe000 seen string of characters, "this test", instead of sequence of bytes.

fortunately, fix quite simple: add "style" value of 1 optional 3rd parameter convert:

select convert(varbinary(max), '0xffd8ffe000', 1); -- 0xffd8ffe000 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -