Can I copy data from one database to another by a sql script? I have an active database we'll call dbo.active and a temp database we'll call dbo.temp both are a customer list and all the customers in dbo.temp exist in dbo.active. I want to copy the notes from dbo.temp to dbo.active and do it by the phone number cause that is the only unique identifier in the 2 databases.

9 Years
Discussion Span
Last Post by freshfitz

You can copy the data from one database to another, but the method depends on whether or not they are located on the same MSSQL Server instance. If they are, then you can qualify the database name like so:

SELECT * FROM active.dbo.CustomerList A
INNER JOIN temp.dbo.CustomerList T
ON A.PhoneNumber = T.PhoneNumber

This statement will select all rows in active's CustomerList table joined to the corresponding CustomerList record in the temp database. Inserting data into the temp database is similar, but using an INSERT statement instead.



How would the insert statement look? That's what I would like to do insert the notes from temp to active

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.