Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8853651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:42:19+00:00 2026-06-14T13:42:19+00:00

I want to insert records in a table with certain values which I got

  • 0

I want to insert records in a table with certain values which I got from a SELECT query on other other tables.

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%'

I want to use the IDs I get from this query to insert in another table Member which use ContaId as a foreign key.

I want to use a WHILE loop, but I don’t know the number of records I will get from the SELECT query.

So, is there a workaround for this problem.

EDIT

This is the table Member

CREATE TABLE [dbo].[Request](
[MemberId] int IDENTITY(1,1) NOT NULL,
    [ContaId] int NOT NULL,
[PromoId] int NOT NULL
);

The PromoId is a non null column, but I want to put the same value for all the records I am about to create.

The Member records have to be like this

 MemberId = Automatic,
 ContaId = // one of the query results,
 PromoId = 91
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:42:20+00:00Added an answer on June 14, 2026 at 1:42 pm

    I want to use the IDs I get from this query to insert in another table
    Member which use ContaId as a foreign key.

    You can use INSERT INTO .. SELECT instead of cursors and while loops like so:

    INSERT INTO Member(ContaId)
    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%'
    

    Update: Try this:

    INSERT INTO Member(ContaId, PromoId)
    SELECT TOP 1000 c.ContaId, 91 AS PromoId
    FROM FastGroupe fg
    ...
    

    This will insert the same value 91 for the PromoId for all the 1000 records. And since the MemberId is set to be automatic, just ignore it in the columns’ list and it will get an automatic value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

greetings all I want to insert 70 records in a table the values are
I want to insert a record into a MySQL database table from a formulaire.
I want to get all records from a table1 & insert them into table2.
I want to insert records in a table with a column having same value
I want to create trigger which will be fired after insert into some table,
I want to insert records into the books table for every author in the
I want to insert n records into a single table. There may be many
I want to insert image in access table. I have all records in DataTable
I wrote a application which uses jdbc to insert records into table A. Now
I want to insert the records that time want to get the visitNo from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.