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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:34:33+00:00 2026-06-03T13:34:33+00:00

Need to port data in sql table I have a master table with columns

  • 0

Need to port data in sql table

I have a master table with columns (masterid, masterdata, year). Here masterid is an identity column.

I have the data for year 2012. I need to same 2012 data for 2013

I could solve the problem by simply running a SQL statement like:

INSERT INTO mastertable
    SELECT masterdata, 2013 
    FROM mastertable WHERE Year = 2012

I would like to run similar kind of run for child table also.

My child table structure is: (childid , masterid, childdata)

Here I have child data for the year 2012, I want to have similar data for year 2013 with proper masterid created for master data for the year 2013 in first step.

Preferably I would like to have solution without adding additional temporary columns

Any lead greatly appreciated.

Regards,
Kumar.

  • 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-03T13:34:34+00:00Added an answer on June 3, 2026 at 1:34 pm

    You’ll need to store the links between the 2013 and 2012 records created in the mastertable table. If you want to achieve this without adding any additional temporary columns you’ll need to use T-SQL.

    (I’ve guessed a type of varchar(max) for masterdata as you haven’t specified its type).

    DECLARE @links TABLE ( masterid int, newmasterid int )
    DECLARE @mastertemp TABLE ( masterid int, masterdata varchar(max) )
    
    DECLARE @masterid int,
            @masterdata varchar(max)
    
    INSERT INTO @mastertemp
    SELECT      masterid,
                masterdata
    FROM        mastertable
    WHERE       [year] = 2012
    
    WHILE EXISTS ( SELECT TOP 1 * FROM @mastertemp )
    BEGIN
        SELECT TOP 1    @masterid = masterid,
                        @masterdata = masterdata
        FROM            @mastertemp
    
        INSERT INTO mastertable
        VALUES ( @masterdata, 2013 )
    
        INSERT INTO @links
        VALUES ( @masterid, SCOPE_IDENTITY() )
    
        DELETE FROM @mastertemp
        WHERE       masterid = @masterid
    END
    
    INSERT INTO childtable
    SELECT      l.newmasterid,
                c.childdata
    FROM        childtable c
    INNER JOIN  @links l ON c.masterid = l.masterid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table of information that I need to find groups of column
I need to send data to a hardware device over serial port. I'm using
I have the following VB.net interface that I need to port to C#. C#
I have a win32 GUI (MFC) application which I need to port to a
I have a Django app that use a django-tagging. I need to port this
I need to rapidly write code to insert/update SQL data. In classic ASP/VBScript I
How can I send data to a specific port and ip? I need to
I have an application where i need to write some data to the serial
I have the request to port a .NET web service to java. I need
I need to port the following from the ASP.NET MVC 2 sourcecode from C#

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.