My comand:
EXEC master..xp_cmdshell 'BCP "SELECT column_of_type_image FROM **your_db WHERE id = 1 " queryout "C:\exportdir\yourfile.pdf" -T -N'
above query run and successfully download the file but images preview not shown
post downloaded that file size is 1 kb only
Best Answer
The
bcp
native datatype for a SQLimage
data type column includes a length prefix that won't be recognized by the rendering application. IMHO,bcp
is not the right tool for this job and invokingxp_cmdshell
in general is a dubious practice from a security perspective.That being said, one way you could export the binary column contents to a file is with a PowerShell command invoked via
xp_cmdshell
: