Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Still on the migration tool I have been working on. My question now is how do I insert records from a table in a database to a table in another database?.( this is actually the main data migration).
I have tried using the SQL "INSERT INTO...SELECT" statements but I am getting errors and I know its because I am connecting to both databases using separate connections.

NB:I have a SOURCE DATABASE which is the database containing tables I will be SELECTING FROM let's call it SOURCE_DB and I am connecting to it using a CONNECTION object called CONN1

NB:I have a DESTINATION DATABASE which is the database containing tables I will be inserting into. Let's call it DEST_DB and I am connecting to it using a CONNECTION object called CONN2

NB:Programming language is C# and database is Sybase SQLAnywhere

Please guys any help, tip or tutorial on how to solve this will be highly appreciated.
Posted

SQL is not my expertise field, but a job-mate of mine had a similar issue, he solved it using:

http://www.mssqltips.com/sqlservertip/1704/using-merge-in-sql-server-to-insert-update-and-delete-at-the-same-time/[^]

I don't know if it can help you directly, but maybe it gives you another point of view to find the way.

(If not you can always try to ask that guy, he looks to know a lot about it)
 
Share this answer
 
v2
You can use query like
select * into [Destination Server][Databasename].[dbo].[Tablename1] from [Source server].[Databasename].[dbo].[Tablename2]


Remember Tablename2 should not present initially.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900