TSQL Pull file into binary field

Ok so i needed a fast way to import a file from the filesystem straight into a binary database field
It couldnt be easier with OPENROWSET.
Here is how

simple as that
Ok so I have an update to make here. In most cases the file your trying to pull up from the filesystem does exist, but wouldnt it be nice to make sure it does before you go ahead, well here’s how do it using xp_fileexist.
I’ve also left the snippet that will tidy up filename UNC’s of the ‘ character. If you tidy it before the file exist test, the test will fail since it already does this. Be sure to leave it between the exist test and the openrowset call.

Leave a Reply

Your email address will not be published. Required fields are marked *