MS SQL Server 2005 Copy data from one table to another

Hi everyone, I am trying to figure out how to copy data from one table to another database table. I have two connections to two different databases. They are called comp-DEV1 and other SQLTEST. Currently, I cannot copy data from my sort table (SQLTEST) to the destination table (comp-DEV1).

This is mistake:

Msg 102, Level 15, State 1, Line 2 Incorrect syntax near '-'.

Query:

INSERT INTO comp-DEV1.EMSSQL.dbo.tblCL SELECT * FROM SQLTEST.EMSSQL.dbo.tblCL WHERE NOT EXISTS(SELECT * FROM comp-DEV1.EMSSQL.dbo.tblCL WHERE (SQLTEST.EMSSQL.dbo.tblCL.CID = comp-DEV1.EMSSQL.dbo.tblCL.CID) ) 

Any help would be great: o)

David

+4
source share
2 answers

Try wrapping your database names in parentheses, for example:

 INSERT INTO [comp-DEV1].EMSSQL.dbo.tblCL SELECT * FROM SQLTEST.EMSSQL.dbo.tblCL WHERE NOT EXISTS(SELECT * FROM [comp-DEV1].EMSSQL.dbo.tblCL WHERE (SQLTEST.EMSSQL.dbo.tblCL.CID = [comp-DEV1].EMSSQL.dbo.tblCL.CID) ) 
+3
source

First, run the following statement to verify that you can read the source from the destination server:

SELECT * FROM [comp-DEV1] .EMSSQL.dbo.tblCL

Get this job first, then you should be on your way ...

0
source

All Articles