Insert into a table several values in a temp table
sql-server, sql-server-2000, t-sql
Solution
Try this:
INSERT INTO IQGroups (GroupID, IQ)
SELECT @GroupID, IQ
FROM #tempIQ
Problem
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) ```