Adding an image file via SQL
February 9, 2011 Leave a comment
To upload a file to field with a type of varbinary(max), use the following:
To update a record
update <TABLE>
set <FIELD> = (Select * FROM OPENROWSET(BULK ‘<PATH>’, SINGLE_BLOB) <FIELD>)
where <FINDRECORD>
To insert a record
insert into <TABLE>
Select
<FIELDS>,
<FIELDNAME>.*
FROM OPENROWSET
(BULK ‘<PATH>’, SINGLE_BLOB) <FIELDNAME>
The path has to be accessible by the SERVER to update. Make sure the varbinary is set to varbinary(max).