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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:14:41+00:00 2026-05-14T05:14:41+00:00

I’ve one situation where I need to copy part of the data from one

  • 0

I’ve one situation where I need to copy part of the data from one server to another. The table schema are exactly same. I need to move partial data from the source, which may or may not be available in the destination table. The solution I’m thinking is, use bcp to export data to a text(or .dat) file and then take that file to the destination as both are not accessible at the same time (Different network), then import the data to the destination. There are some conditions I need to satisfy:

  1. I need to export only a list of data from the table, not whole. My client is going to give me IDs which needs to be moved from source to destination. I’ve around 3000 records in the master table, and same in the child tables too. What I expect is, only 300 records to be moved.
  2. If the record exists in the destination, the client is going to instruct as whether to ignore or overwrite case to case. 90% of the time, we need to ignore the records without overwriting, but log the records in a log file.

Please help me with the best approach. I thought of using BCP with query option to filter the data, but while importing, how do I bypass inserting the existing records? How do I overwrite, if that is needed?

  • 1 1 Answer
  • 1 View
  • 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-05-14T05:14:41+00:00Added an answer on May 14, 2026 at 5:14 am

    Unfortunately BCPing into a table is an all or nothing deal, you can’t select rows to bring in.

    What I’d do is . . .

    1. Create a table on the source
      database, this will store the ID’s
      of the rows you need to move. You
      can now BCP out the rows that you
      need.
    2. On the destination database, create
      a new Work In Progress table, and
      BCP the rows in there.
    3. Once in there you can write a script
      that will decide whether or not a
      WIP row goes into the destination
      table, or not.

    Hope this helps.

    Update

    By work in progress (WIP) tables I don’t mean #temp tables, you can’t BCP into a temp table (at least I’d be very sprprised if you could).
    I mean a table you’d create with the same structure of the destination table, bcp into that, script the WIP rows to the destination table then drop the WIP table.

    You haven’t said what RDBMS you’re using, assuming SQL Server, something like the following (untried code) . . .

    -- following creates new table with identical schema to destination table
    select * into WIP_Destination from Destination
    where 1 = 0
    
    -- BCP in the rows
    BULK INSERT WIP_Destination from 'BcpFileName.dat'
    
    -- Insert new rows into Destination
    insert into Destination
    Select * from WIP_Destination 
    where not id  in (select id from Destination)
    
    -- Update existing rows in destination
    
    Update Destination 
    set field1 = w.field1, 
        field2 = w.field2, 
        field3 = w.field3, 
        . . . 
    from Destination d inner join WIP_Destination w on d.id = w.id
    
    Drop table WIP_Destination
    

    Update 2
    OK, so you can insert into temporary tables, I just tried it (I didn’t have time the other day, sorry).

    On the problem of the master/detail records (and we’re now moving off the subject of the original question, if I were you I’d open a new question for this topic, you’ll get more answers than just mine)

    You can write an SP that will step through the new rows to add.
    So, you’re looping through the rows in your temp table (these rows have the original id on them from the source database), insert that row into the Destination table, use SCOPE_IDENTITY to get the id of the newly inserted row. Now you have the old Id and the new ID, you can create an insert statement that will insert statement for the detail rows like . . .

    insert into Destination_Detail
    select @newId, field1, field2 . . . from #temp_Destination_Detail
    where Id = @oldId
    

    Hope this helps [if it has helped you are allowed to upvote this answer, even if it’s not the answer you’re going to select :)]

    Thanks
    BW

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I

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.