I have a set of audio files with names GreenLine1.mp3, GreenLine2.mp3 e.t.c. I\'m going to write them into a table as BLOB (I use MS SQL Server\'08), here\'s my sql request:
You can't parametrise or concatenate the parameters of OPENROWSET. It is constant values only.
You'll have to use dynamic SQL and a temp table, or consider using SSIS for example
This article pointed me in the right direction when I had the same issue with OPENQUERY:
https://web.archive.org/web/20120724073530/http://consultingblogs.emc.com/jamespipe/archive/2007/06/28/SQL-Server-2005_3A00_-Passing-variables-into-an-OPENQUERY-argument.aspx
Basically, you can wrap the entire statement in a variable (nvarchar), including the openrowset, and run exec sp_executesql @sql
. It gets a little ugly to read around the '
s though, because you'll have to escape them with ''
.