SQL查询:从不同的服务器将一个表复制到另一个表

时间:2022-10-22 00:14:05

What's wrong with my query, I want to copy three columns to another server\table if one of the column (ID_DIRCT) is not null :

我的查询有什么问题?如果其中一列(ID_DIRCT)不是空的,我想将三列复制到另一个服务器\表:

INSERT INTO  System\Syst3.Server1.dbo.TABLE_RESRC (NO_EMPLY,PR,NM_FAML,CO_DIRCT)
SELECT NO_EMPLY, PR_EMPLY, NM_EMPLY, ID_DIRCT 
FROM System\Syst3.Server2.dbo.RESRC
WHERE System\Syst3.Server2.dbo.RESRC.ID_DIRCT IS NOT NULL

Using SQL Server 2008 R2.

使用SQL Server 2008 R2。

Thanks.

谢谢。

1 个解决方案

#1


3  

You don't state wether you are getting an error, or wrong results or anything like that, you don't even say what RDBMS you are using. So, an educated guess of what's wrong with your query is that you are not using quotes to call your linked server (it needs them because of some special chars in the name of the linked server):

你不会说你得到了一个错误,或者错误的结果或者类似的东西,你甚至不会说你在使用什么RDBMS。因此,对您的查询有错误的猜测是,您没有使用引号来调用链接服务器(它需要它们,因为链接服务器的名称中有一些特殊的字符):

INSERT INTO  [System\Syst3].Server1.dbo.TABLE_RESRC (NO_EMPLY,PR,NM_FAML,CO_DIRCT)
SELECT NO_EMPLY, PR_EMPLY, NM_EMPLY, ID_DIRCT 
FROM [System\Syst3].Server2.dbo.RESRC A
WHERE A.ID_DIRCT IS NOT NULL

#1


3  

You don't state wether you are getting an error, or wrong results or anything like that, you don't even say what RDBMS you are using. So, an educated guess of what's wrong with your query is that you are not using quotes to call your linked server (it needs them because of some special chars in the name of the linked server):

你不会说你得到了一个错误,或者错误的结果或者类似的东西,你甚至不会说你在使用什么RDBMS。因此,对您的查询有错误的猜测是,您没有使用引号来调用链接服务器(它需要它们,因为链接服务器的名称中有一些特殊的字符):

INSERT INTO  [System\Syst3].Server1.dbo.TABLE_RESRC (NO_EMPLY,PR,NM_FAML,CO_DIRCT)
SELECT NO_EMPLY, PR_EMPLY, NM_EMPLY, ID_DIRCT 
FROM [System\Syst3].Server2.dbo.RESRC A
WHERE A.ID_DIRCT IS NOT NULL