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

后端 未结 2 1195
甜味超标
甜味超标 2021-02-13 03:20

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

insert into imageTable(imageField) 
values(convert(image, 0x3C3F78...))

how

相关标签:
2条回答
  • 2021-02-13 03:48

    This is correct for 0x0: each pair of digits makes one byte so 0x00 has the value stored

    When I run SELECT convert(varbinary(max), 0x55) I get 0x55 out on SQL Server 2008. SELECT convert(varbinary(max), 85) gives me 0x00000055 which is correct is 85 is a 32 bit integer

    What datatype are you casting to varbinary?

    Edit: I still can't reproduce using image not varbinary

    Some questions though:

    • is this an upgraded database? What is the compatibility level?
    • why use image: use varbinary(max) instead
    • what happens when you change everything to varbinary?
    0 讨论(0)
  • 2021-02-13 04:05

    I have just had similar problem and I blame myself.

    It is possible, that you copy just part of data you need. In my case, I added '0' to the end of the blob.

    The cause of this could be copying the value from SQL Management Studio to clipboard.


    insert into imageTable(imageField) values(0x3C3F78...A)

    Select returned: 0x03C3F78...


    insert into imageTable(imageField) values(0x3C3F78...A 0 )

    Select returned: 0x3C3F78...


    I hope this will help.

    Best wishes.

    0 讨论(0)
提交回复
热议问题