0
declare @strSQL nvarchar(max)
set @strSQL = '
select * from HumanResources.Department where Name = @Name1
union all
select * from HumanResources.Department where Name = @Name2
'

Exec sp_executesql @strSQL, 
  N'@Name1 nvarchar(max)', 'Engineering', 
  N'@Name2 nvarchar(max)', 'Tool Design'

这是一个愚蠢的例子,但它会解决我的问题(Adventureworks 演示)。请问如何将第二个参数(@Name2)放入 sp_ExecuteSQL,它只获取第一个参数(@Name1)?

4

0 回答 0