Hussein Zahran
asked on
Issue with using a SELECT statement with OPENROWSET function
Hello
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:
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:
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hussein, do you still need help with this question?