save any file to pc

  • hi all.

    I use below command for retrive varbinary column data and save to local pc,this command saved file with same size with original file,but not open file correctly.what I do for this problem?

    declare @SQLcommand nvarchar(4000)

    set @SQLcommand = 'bcp "SELECT Photo FROM Attachments WHERE [ImageName] = ''Picture.bmp'' " queryout "C:\PicutureOut.bmp" -T -N -SServerName'

    exec xp_cmdshell @SQLcommand

  • Elham,

    I think part of the problem might be that you stated that the file is stored as varbinary( nn ) data-type, yet you are pulling the file back into a nvarchar( 4000 ) data-type. I think that you must use varbinary data-type when you extract the file back out to disk too.

    I'm pretty sure that the "N" in the data-type designates that it is uni-code characters which equates to 2-bytes per character. My guess is that it pulls one byte out of your varbinary data field and then creates a 2-byte character out of the single byte.

    Try matching both data-types to varbinary and see if that fixes it.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply