Search code examples
sqlsql-serverstored-proceduresvarbinarymax

How to update varbinary(max) column with path stored in varchar column?


I currently have a varchar(255) column that stores the path to a small image file. I want to try to load the file into a new column of type varbinary(max), but don't know how to write a stored procedure to do such. Something like such

UPDATE MyTable
SET image = "file located in field imagePath"

I know that makes no sense because I don't have a where clause, but what would I put in it's place??


Solution

  • SQL is not well suited to accessing the file system, but this task would not be difficult to accomplish in a C#/VB.NET program.

    EDIT: Tim Lehner's OPENROWSET solution is ideal if you are on SQL 2005 or later.