To copy between databases you have to qualify the tables with their
database: DBName.User_Schema.TableName
To insert the data into existing table you have to list the columns when
running the statement. If you do not want to copy the exact values of the
IDENTITY column you can exclude it from the list, it will automatically
generate values in the target table. If you want to copy the values, then
set IDENTITY_INSERT to ON.
Examples below assuming the tables are under the 'dbo' user/schema:
1) Without IDENTITY column:
INSERT INTO DatabaseB.dbo.patients_visits (column1, column2, ...)
SELECT column1, column2, ... FROM DatabaseA.dbo.patients_visits
2). With IDENTITY column - set IDENTITY_INSERT to ON:
SET IDENTITY_INSERT DatabaseB.dbo.patients_visits ON
INSERT INTO DatabaseB.dbo.patients_visits (ident_column, column1, column2,
....)
SELECT ident_column, column1, column2, ... FROM
DatabaseA.dbo.patients_visits
HTH,
Plamen Ratchev
http://www.SQLStudio.com