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 7846259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:31:17+00:00 2026-06-02T17:31:17+00:00

I have a few tables in SQL that are pretty much like this A

  • 0

I have a few tables in SQL that are pretty much like this

A            B           C
ID_A         ID_B        ID_C
Name         Name        Name
             ID_A        ID_B

As you can see, A is linked to B and B to C. Those are basically tables that contains data models. Now, I would need to be able to create date based on those tables. For example, if I have the following datas

A                    B                        C
1    Name1           1  SubName1   1          1  SubSubName1  1
2    Name2           2  SubName2   1          2  SubSubName2  1
                     3  SubName3   2          3  SubSubName3  2
                                              4  SubSubName4  3
                                              5  SubSubName5  3

I would like to copy the ‘content’ of those tables in others tables. Of course, the auto numeric key that is generated when inserting into the new tables are diffirent that those one and I would like to be able to keep track so that I can copy the entire thing. The structure of the recipient table contains more information that those, but it’s mainly dates and other stuff that are easy to get for me.

I would need to this entirely in TRANSACT-SQL (with built-in function if needed). Is this possible and can anyone give me a short example. I manage to do it for one level, but I get confused for the rest.

thanks

EDIT : The info above is just an example, because my actual diagram looks more like this

Model tables :

Processes -- (1-N) Steps -- (1-N) Task             -- (0-N) TaskCheckList
                         -- (0-N) StepsCheckLists

Where as the table I need to fill looks like this

Client -- (0-N) Sequence -- (1-N) ClientProcesses -- (1-N) ClientSteps -- (1-N)ClientTasks -- (0-N) ClientTaskCheckList
                                                                       -- (0-N)ClientStepCheckLists

The Client already exists and when I need to run the script, I create one sequence, which will contains all processes, which will contains its steps, taks, etc…

  • 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-02T17:31:18+00:00Added an answer on June 2, 2026 at 5:31 pm

    Ok,

    So I did a lot of trials and error, and here is what I got. It seems to work fine although it sound quite big for something that seemed easy at first.

    The whole this is somehow in french and english because our client is french and so are we anyway. It does insert every date in all tables that I needed. The only thing left to this will be the first lines where I need to select the date to insert according to some parameters but this is the easy part.

    DECLARE @IdProcessusRenouvellement bigint
    DECLARE @NomProcessus nvarchar(255)
    
    SELECT @IdProcessusRenouvellement = ID FROM T_Ref_Processus WHERE Nom LIKE 'EXP%'
    SELECT @NomProcessus = Nom FROM T_Ref_Processus WHERE Nom LIKE 'EXP%'
    
    DECLARE @InsertedSequence table(ID bigint)
    
    DECLARE @Contrats table(ID bigint,IdClient bigint,NumeroContrat nvarchar(255))
    
    INSERT INTO @Contrats SELECT ID,IdClient,NumeroContrat FROM T_ClientContrat
    
    DECLARE @InsertedIdsSeq as Table(ID bigint)
    
    -- Séquences de travail
    INSERT INTO T_ClientContratSequenceTravail(IdClientContrat,Nom,DateDebut)
        OUTPUT Inserted.ID INTO @InsertedIdsSeq
        SELECT ID, @NomProcessus + ' - ' + CONVERT(VARCHAR(10), GETDATE(), 120) + ' : ' +     NumeroContrat ,GETDATE() 
        FROM @Contrats
    
    -- Processus
    DECLARE @InsertedIdsPro as Table(ID bigint,IdProcessus bigint)
    INSERT INTO T_ClientContratProcessus
            (IdClientContratSequenceTravail,IdProcessus,Nom,DateDebut,DelaiRappel,DateRappel,LienAvecPro    cessusRenouvellement,IdStatutProcessus,IdResponsable,Sequence)
        OUTPUT Inserted.ID,Inserted.IdProcessus INTO @InsertedIdsPro
        SELECT     I.ID,P.ID,P.Nom,GETDATE(),P.DelaiRappel,GETDATE(),P.LienAvecProcessusRenouvellement,0,0,0
            FROM @InsertedIdsSeq I, T_Ref_Processus P 
            WHERE P.ID = @IdProcessusRenouvellement
    
    -- Étapes
    DECLARE @InsertedIdsEt as table(ID bigint,IdProcessusEtape bigint)
    INSERT INTO T_ClientContratProcessusEtape 
            (IdClientContratProcessus,IdProcessusEtape,Nom,DateDebut,DelaiRappel,DateRappel,NomListeVeri    fication,Sequence,IdStatutEtape,IdResponsable,IdTypeResponsable,ListeVerificationTermine)
        OUTPUT Inserted.ID,Inserted.IdProcessusEtape INTO @InsertedIdsEt
    SELECT I.ID,E.ID,
                E.Nom,GETDATE(),E.DelaiRappel,GETDATE(),COALESCE(L.Nom,''),E.Sequence,0,0,E.IdTypeResponsabl    e,0
    FROM @InsertedIdsPro I INNER JOIN  T_Ref_ProcessusEtape E ON I.IdProcessus =     E.IdProcessus
    LEFT JOIN T_Ref_ListeVerification L ON E.IdListeVerification = L.ID
    
    -- Étapes : Items de la liste de vérification   
    INSERT INTO T_ClientContratProcessusEtapeListeVerificationItem
        (IdClientContratProcessusEtape,Nom,Requis,Verifie)  
        SELECT I.ID,IT.Nom,IT.Requis,0
        FROM @InsertedIdsEt I 
        INNER JOIN T_Ref_ProcessusEtape E ON I.IdProcessusEtape = E.ID
        INNER JOIN T_Ref_ListeVerificationItem IT ON E.IdListeVerification =     IT.IdListeVerification
    
    -- Tâches
    DECLARE @InsertedIdsTa as table(ID bigint, IdProcessusEtapeTache bigint)
    INSERT INTO T_ClientContratProcessusEtapeTache
            (IdClientContratProcessusEtape,IdProcessusEtapeTache,Nom,DateDebut,DelaiRappel,DateRappel,No    mListeVerification,Sequence,IdStatutTache,IdResponsable,IdTypeResponsable,ListeVerificationT    ermine)
        OUTPUT Inserted.ID,Inserted.IdProcessusEtapeTache INTO @InsertedIdsTa
        SELECT I.ID,T.ID,
                   T.Nom,GETDATE(),T.DelaiRappel,GETDATE(),COALESCE(L.Nom,''),T.Sequence,0,0,T.IdTypeResponsabl    e,0
        FROM @InsertedIdsEt I 
        INNER JOIN T_Ref_ProcessusEtapeTache T ON I.IdProcessusEtape = T.IdProcessusEtape
        LEFT JOIN T_Ref_ListeVerification L ON T.IdListeVerification = L.ID
    
    
    -- Tâches : Items de la liste de vérification
    INSERT INTO T_ClientContratProcessusEtapeTacheListeVerificationItem
        (IdClientContratProcessusEtapeTache,Nom,Requis,Verifie) 
        SELECT I.ID,IT.Nom,IT.Requis,0
        FROM @InsertedIdsTa I 
        INNER JOIN T_Ref_ProcessusEtapeTache T ON I.IdProcessusEtapeTache = T.ID
        INNER JOIN T_Ref_ListeVerificationItem IT ON T.IdListeVerification =     IT.IdListeVerification
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few huge tables on a production SQL 2005 DB that need
I have a few SQL Server tables with a datetime field that really only
I have a large (100+ tables) SQL Server 2005 database that I would like
We have a few tables with persisted computed columns in SQL Server. Is there
I have a few thousand tables in my SQL Server instance, and I need
I have a few tables with 70-80 columns in them. I would like to
I have a database with few tables, ex.: Employee (Id, Name, state, country) Material
We have a few tables in our SQL Server (2005 & 2008) database with
I have a database with a few tables running on SQL Server 2008, and
I created a SQL View that joins a few tables and when tested in

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.