title: SQL Server 2008 insert into table using loop
body: <p>I want to insert records in a table with certain values which I got from a <code>SELECT</code> query on other other tables.</p>
  
  <pre><code>SELECT TOP 1000 c.ContaId
  FROM FastGroupe fg
  INNER JOIN FastParticipant fp 
      ON fg.FastGroupeId = fp.FastGroupeId
  INNER JOIN Participant p
      ON fp.ParticipantId = p.ParticipantId
  INNER JOIN Contact c
      ON p.ContaId = c.ContaId
  WHERE FastGroupeName like '%Group%'
  </code></pre>
  
  <p>I want to use the IDs I get from this query to insert in another table <code>Member</code> which use <code>ContaId</code> as a foreign key.</p>
  
  <p>I want to use a <code>WHILE</code> loop, but I don't know the number of records I will get from the <code>SELECT</code> query.</p>
  
  <p>So, is there a workaround for this problem.</p>
  
  <p>EDIT</p>
  
  <p>This is the table <code>Member</code></p>
  
  <pre><code>CREATE TABLE [dbo].[Request](
  [MemberId] int IDENTITY(1,1) NOT NULL,
      [ContaId] int NOT NULL,
  [PromoId] int NOT NULL
  );
  </code></pre>
  
  <p>The <code>PromoId</code> is a non null column, but I want to put the same value for all the records I am about to create.</p>
  
  <p>The <code>Member</code> records have to be like this</p>
  
  <pre><code> MemberId = Automatic,
   ContaId = // one of the query results,
   PromoId = 91
  </code></pre>