user194076
user194076

Reputation: 9017

how to pass parameter with quotation marks

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

Answers (1)

gbn
gbn

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

Related Questions