How to import an image from a file, using OPENROWSET, to a table record?
3
votes
2
answers
313
views
I am trying to import a small image from a file located on my MS SQL Server to a column in a database setup as
VARBINARY(MAX)
. I have declared a variable as VARBINARY(MAX)
and would like to assign the image to that variable. Once assigned I have to locate the records and store that image to those records. I have a query that works to store the image to the column, but for the life of me I cannot import new images from files on the servers SSD.
USE [Mydb]
DECLARE @ImageFile VARBINARY(MAX)
SELECT @ImageFile = 'Abracon.jpg'
FROM
OPENROWSET(BULK 'C:\Users\admin\Pictures\Abracon.jpg', SINGLE_BLOB)
AS BLOB;
Running this query gives me the following error:
> Msg 257, Level 16, State 3, Line 16
>
>Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.
I read the OPENROWSET
page at learn.microsoft.com, but I still don't see my error.
What am I doing wrong?
Asked by Gromit
(33 rep)
Jul 14, 2025, 10:09 PM
Last activity: Jul 15, 2025, 10:42 PM
Last activity: Jul 15, 2025, 10:42 PM