我想运行此查询
INSERT INTO [tblPollLogs]
([lastModified]
,[ip]
,[a1]
,[a2]
)
VALUES
(getdate()
,'aaa'
,(select top 1 header from [tblPollAnswer] where [pollAnswerId] = @param1)
,(select top 1 header from [tblPollAnswer] where [pollAnswerId] = @param2)
)
但是我收到了错误
在此上下文中不允许使用子查询。只允许使用标量表达式。
我可以在一个查询中运行此查询,或者我需要在运行此查询之前获取值
感谢
答案 0 :(得分:5)
尝试将其更改为insert...select
,如下所示
INSERT INTO [tblPollLogs]
([lastModified]
,[ip]
,[a1]
,[a2]
)
select getdate(),
'aaa',
(select top 1 header from [tblPollAnswer] where [pollAnswerId] = @param1),
(select top 1 header from [tblPollAnswer] where [pollAnswerId] = @param2)