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.

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.

HTH,
darkagn

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.