Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert into a table several values in a temp table

I have several values in a temp table called #tempIQ and I want to insert into a table called IQGroups using the same Group identifier. Assuming everyone has a unique IQ:

create table #tempIQ
(
id int
)

declare @GroupIDas int
set @GroupID=1001    

select iq from #tempIQ

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

I want to insert these ids from the temp table into a grouping called IQGroups but am having difficulty finding a simple solution.

-- 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) 
like image 879
RetroCoder Avatar asked Aug 06 '26 11:08

RetroCoder


1 Answers

Try this:

 INSERT INTO IQGroups (GroupID, IQ)
   SELECT @GroupID, IQ
   FROM #tempIQ
like image 81
marc_s Avatar answered Aug 08 '26 09:08

marc_s