0

So in setting the test environment for SQL Agent job I'm working on I populated a varbinary(max) field from a pdf file on disc using OPENROWSET like so

DECLARE @File varbinary(max)
SELECT @File=BulkColumn
FROM OPENROWSET 
    (BULK 'v:\DIMA.pdf', SINGLE_BLOB) pdf

UPDATe Invoice_FileList SET Fajl=@File WHERE ID=4 

Afterwards I write the file back to disc like so

DECLARE @bcpCommand nvarchar(1000), @ID bigint, @UID bigint
DECLARE @FileName nvarchar(256), @FileDir nvarchar(128) = 'v:\'

SELECT @ID=ID, @UID=UID, @FileName =@FileDir + ImeFajla FROM ABImport_ImmoF.dbo.Invoice_FileList WHERE ID=4 

SET @bcpCommand = 'bcp "SELECT Fajl FROM ABImport_ImmoF.dbo.Invoice_FileList WHERE ID = ' + CAST(@ID AS VARCHAR(20)) + ' AND UID = ' + CAST(@UID AS VARCHAR(20))  + '" queryout "' + @FileName + '" -T -N -S ' + @@SERVERNAME
print @bcpCommand
EXEC master..xp_cmdshell @bcpCommand

Everything seemingly works fine, but the original pdf file and the file bcp saves to disk differ in size by few bytes and while looking identical when opened in pdf reader, comparing their respective hex shows that they are very much different.

Can someone explain to me why is that so (and since they are looking the same when opened in pdf reader do I need to worry about it at all)

0 Answers0