Insert hex string value to sql server binary field is appending extra 0

Posted by rotary_engine on Stack Overflow See other posts from Stack Overflow or by rotary_engine
Published on 2010-04-17T09:33:09Z Indexed on 2010/04/17 9:43 UTC
Read the original article Hit count: 208

Filed under:

Have a binary field and want to insert into this from a hex string:

insert into binaryTable(binaryField) values(convert(varbinary(max), 0x0))

however when I run select the value is return with an extra 0 as 0x00

This extra 0 is causing a problem in another application, I dont want it.

Interesting, is if I do a select on an existing value and it returns say 0x55 then inserting this same value using the above query will return a select of 0x055.

How to stop the extra 0 being added?

© Stack Overflow or respective owner

Related posts about sql-server-2008