I use the following SELECT stategemt when I try to upload a file from a local path into a table that has a varbinary(MAX) column:
SELECT BulkColumn FROM OPENROWSET(BULK 'D:\MyFolder\Image01.bmp', SINGLE_BLOB) rs
This works for me, however; there is a need for me to pass the 'D:\MyFolder\Image01.bmp' as a variable in the SELECT statement above. For example:
DECLARE @MY_VAR VARCHAR(100)
SELECT @MY_VAR = 'D:\MyFolder\Image01.bmp'
SELECT BulkColumn FROM OPENROWSET(BULK @MY_VAR, SINGLE_BLOB) rs
When I do this and run the query, I get the following error message from the server:
Incorrect syntax near '@MY_VAR'
Any idea why and how to resolve this using a variable that carries the path rather than passing the path itself in the SELECT statement?