在临时表中插入表中的几个值

Ret*_*der 3 t-sql sql-server sql-server-2000

我在名为#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
Run Code Online (Sandbox Code Playgroud)

我想将这些来自临时表的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) 
Run Code Online (Sandbox Code Playgroud)

mar*_*c_s 7

试试这个:

 INSERT INTO IQGroups (GroupID, IQ)
   SELECT @GroupID, IQ
   FROM #tempIQ
Run Code Online (Sandbox Code Playgroud)