Jerry Nixon @Work: The TSQL to insert an image/blog

Jerry Nixon on Windows

Friday, March 13, 2009

The TSQL to insert an image/blog

I recently needed this syntax.

If you want to insert a local file into a database image field (varbinary(max) field) then this is the syntax:

CREATE TABLE MyTable 
(id int, image varbinary(max))

INSERT INTO MyTable
SELECT 1
,(SELECT * FROM OPENROWSET(
BULK 'C:\file.bmp', SINGLE_BLOB) as x )