Storing an Excel File in a SQL Server Database

If you have a table with an image data type field where you store an Excel file or any file for that matter, and you need to update a particular record with a new file, you can use OPENROWSET.

UPDATE MyTable
SET MyImageField = (
    SELECT * 
    FROM OPENROWSET(BULK N'C:\MyExcelFile.xls', SINGLE_BLOB) AS MyFile
)
FROM MyTable
WHERE ...

 

 

One disadvantage of using this is that the file you are storing needs to be accessible by the SQL Server.