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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s