0

我想运行这个查询

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)         
         )

但我得到了错误

在这种情况下不允许子查询。只允许标量表达式。

我可以在一个查询中运行此查询还是需要在运行此查询之前获取值

谢谢

4

1 回答 1

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)         
于 2013-09-10T09:37:20.580 回答