T-SQL: issue with string concat

前端 未结 2 989
醉酒成梦
醉酒成梦 2020-12-18 21:55

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:

相关标签:
2条回答
  • 2020-12-18 22:36

    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

    0 讨论(0)
  • 2020-12-18 22:51

    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 ''.

    0 讨论(0)
提交回复
热议问题