Jerry Nixon on Windows: The TSQL to insert an image/blog

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 )