Click here to Skip to main content
16,001,007 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL server 2012 Directly i have insert in varbinary(max) column from image value. Last 1 digits missing and value before 2 character after 0 added why? and i cant construct image

What I have tried:

here sample Sql server Query

1) here zero not added ? i want in this format only
SQL
declare @data varbinary(max)
set @data = 0xFFD8FFE0
select  @data

soln:-
0xFFD8FFE0

2) here zero added ?
SQL
declare @data1 varbinary(max)
set @data1 = 0xFFD8FFE00
select  @data1

soln:-
0x0FFD8FFE00



kindly give me a solution .....
Posted
Updated 20-Nov-17 18:03pm
v3
Comments
Richard MacCutchan 20-Nov-17 7:14am    
The results correspond exactly with the data you are inserting.

1 solution

When I run your code, I get exactly what I expect:
SQL
declare @data varbinary(max)
set @data = 0xFFD8FFE0
select  @data

declare @data1 varbinary(max)
set @data1 = 0xFFD8FFE00
select  @data1

Gives
(No column name)
0xFFD8FFE0

(No column name)
0x0FFD8FFE00
Which is correct.
The problem is that you are expecting a "leading zero" on the first number, and it doesn't exist. When you store data in a VARBINARY column, it is stored as bytes - 8 bit unsigned quantities. but the data you enter is treated as pairs of hex digits, starting with the right hand end. So 0xFFD8FFE0 is stored as bytes:
C#
FF D8 FF E0
and 0xFFD8FFE00 is stored as
0F FD 8F FE 00

If you don't provide an even number of digits, a "leading zero" is inserted in the data, as I would expect.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900