Reputation: 9017
I can do this in my query:
SELECT * FROM OPENROWSET(BULK 'C:\myPC.file', SINGLE_BLOB)
but how do I do this?
Declare @Var = 'C:\myPC.file'
SELECT * FROM OPENROWSET(BULK @Var, SINGLE_BLOB)
I tried three '''
single quotes, but still says incorrect syntax.
Upvotes: 2
Views: 1800
Reputation: 432210
You can not parametrise OPENROWSET (or OPERNQUERY etc). Constants only.
Declare @Var = 'C:\myPC.file';
Declare @SQL varchar(1000);
SET @SQL = 'SELECT * FROM OPENROWSET(BULK ''' + @Var + ''', SINGLE_BLOB)';
EXEC (@sql)
Upvotes: 7