简体   繁体   English

链接服务器上的OPENQUERY更新

[英]OPENQUERY update on linked server

I want to execute the following statement through from a linked server (openquery): 我想通过链接服务器(openquery)执行以下语句:

UPDATE SAP_PLANT 
SET (OWNER, OWNER_COUNTRY) = (SELECT import.AFNAME, import.COUNTRY
                                FROM SAP_IMPORT_CUSTOMERS import, SAP_PLANT plant
                                WHERE plant.SAP_FL = import.SAP_NO
                                AND import.role ='OWNER')

I've tried to form it into the following syntax, without success :( 我试图将其形成以下语法,但没有成功:(

update openquery(‘my_linked_server, ‘select column_1, column_2 from table_schema.table_name where pk = pk_value’)
set column_1 = ‘my_value1′, column_2 = ‘my_value2′

I hope for you this is no problem? 希望对你没问题吗?

I guess this is not really a query you want to open, rather an SQL statement you want to execute. 我想这并不是您要打开的查询,而是您要执行的SQL语句。 So instead of openquery, you shoud use execute. 因此,您应该使用execute而不是openquery。 See example G here: http://msdn.microsoft.com/en-us/library/ms188332.aspx 请在此处查看示例G: http : //msdn.microsoft.com/en-us/library/ms188332.aspx

So your script shoul look like 所以你的脚本应该看起来像

execute ('your sql command here') at my_linked_server

Are you getting syntax error? 您是否收到语法错误? Your server parameter in the update openquery is missing a trailing quote. 您在update openquery中的服务器参数缺少尾随引号。 Change ```my_linked_server to my_linked_server'`. 将```my_linked_server更改to my_linked_server'`。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM