Reputation: 3024
I have this query in place that exports the files from a database to the original format. I run it in SQL Management Studio, hence the EXEC at the end to export the file using BCP.
SELECT @sql = 'BCP "SELECT rawdata
FROM AttachedFile
WHERE id = ' + @id_row + '"
queryout ' + @OutputFilePath + @id_row + '_' + file_name + ' -S SERV001\SQLINST -T -N'
FROM AttachedFile
WHERE id = @id_row
EXEC xp_cmdshell @sql, NO_OUTPUT
The database contains raw data of various file types. The only ones that are exported correctly are PDF files. JPG files appear to be corrupted and they cannot be read by any type of software.
The exported JPG files contain data and there is no error at the export, so I believe the problem is with the file headers, yet I am not sure how to correct it.
Upvotes: 2
Views: 409