SQL Server 2005/2008: Insert a File in an varbinary(max) column in Transact-SQL
22,777
It's so easy - once you know it! :-) Found this on Greg Duncan's blog a while ago:
INSERT INTO YourTable(YourVarbinaryColumn)
SELECT * FROM
OPENROWSET(BULK N'(name of your file to import)', SINGLE_BLOB) AS import
And here's the MSDN library documentation on it.
Marc
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on August 01, 2020Comments
-
Admin almost 4 years
Is it possible to insert a file in a varbinary(max) column in Transact-SQL? If yes, I would be very please to have a code snippet to at least give me an idea how to do that.
Thanks
-
Tony almost 13 yearsremember the path to the file is relative to the SQL server. So if it is C:\test.txt that is on the c: drive of the computer the sql server instance is running on.
-
IanGSY over 8 yearsNote that the AS import at the end is very important!