为什么我不能使用结果集作为存储过程的输入?
错误:
Msg 102,Level 15,State 1,Line 2
附近的语法不正确
'('。
代码:
EXECUTE [dbo].[spUpdateTrade]
@statusID = (SELECT [ID] FROM [dbo].[dimStatus] WHERE [name] = 'Inactive'),
@ID = 2
答案 0 :(得分:2)
首先需要将结果保存到变量中,然后可以使用:


 DECLARE @pStatusId INT;
 SELECT @pStatusId = [ID] FROM [dbo]。[dimStatus] WHERE [name] ='Inactive';
 EXECUTE [dbo]。[spUpdateTrade] @statusID = @pStatusId,@ ID = 2



答案 1 :(得分:1)
Declare @id int
select @id=[ID] FROM [dbo].[dimStatus] WHERE [name] = 'Inactive'--risk of getting last value in case of multiple values
EXECUTE [dbo].[spUpdateTrade]
@statusID =@id,
@ID = 2