3

我在一个名为 #tempIQ 的临时表中有几个值,我想使用相同的组标识符插入一个名为 IQGroups 的表中。假设每个人都有一个独特的智商:

create table #tempIQ
(
id int
)

declare @GroupIDas int
set @GroupID=1001    

select iq from #tempIQ

1,2,86,99,101,165,180,201

我想将临时表中的这些 id 插入一个名为 IQGroups 的分组中,但我很难找到一个简单的解决方案。

-- now try and insert all the iqs for a group into the IQGroups table from the #tempIQ table.
  insert into IQGroups (GroupID, IQ) values (@GroupID, #tempiQ.iq) 
4

3 回答 3

7

试试这个:

 INSERT INTO IQGroups (GroupID, IQ)
   SELECT @GroupID, IQ
   FROM #tempIQ
于 2012-06-20T19:47:45.003 回答
3

尝试使用 SELECT 语句。

INSERT INTO IQGroups (GroupID, IQ)
SELECT @GroupID, iq
FROM #tempIQ

这是选择多行的标准方法。

于 2012-06-20T19:48:28.993 回答
0

这是另一种方法,

select id, 1001 as GroupID
into IQGroups 
from #tempIQ
于 2012-06-20T21:30:20.310 回答